npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hellomelo/expressplus

v1.1.3

Published

Simple framework for creating websites with ease.

Downloads

6

Readme

ExpressPlus

ExpressPlus is a simple framework designed to create webpages with ease.

Routing

Creating a new ExpressPlus instance, with the port being 3000:

const ExpressPlus = require('@hellomelo/expressplus');
const exp = new ExpressPlus(3000);

Creating the path /page as a GET method, that returns Hello, World!

exp.route('/page', 'get', function (req) {
	return 'Hello, world!';
});

Getting Data

The req object returns:

  • ip: The user's IP address, as a string.
  • params: The URL parameter values, as a JSON object. i.e. if your path is /users/:name, and the user visits /users/hello, params.name would return "hello"
  • query: The URL query parameters, as a JSON object.
  • body: Returns the JSON body of the request.
  • protocol: Returns the protocol. (i.e. https)
  • xhr: Returns true if the method is using xhr, and false otherwise.
  • path: Returns the URL path.
  • host: Returns the hostname (i.e. example.com)
  • headers: A list of the headers, as an array.

exp.parse(content, title, options)

This option would return the provided content tag as a full HTML page. Example:

exp.parse(`<h1>Hello, World!</h1>`, 'home', {});

would return:

<!DOCTYPE html>
<html>
<head>
<title>home</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>

Options (all optional)

  • head: HTML that should appear in the head tag, above the default title tag.
  • nav: HTML that should appear at the top of the body tag. Commonly used to display the navigation bar.
  • footer: HTML that should appear at the bottom of the body tag.

exp.rd(route, content)

Creates a page that redirects to the route provided, with the message provided.

exp.route('/admin', 'get', function (req) {
  if (!admin) return exp.rd("/", "403 — Redirecting...");
});

Routing Example

const ExpressPlus = require('@hellomelo/expressplus');

const exp = new ExpressPlus(3000);
const options = { nav: `<div id="nav"></div>` };

exp.route('/', 'get', function (req) {
  return exp.parse(`
  <h1>Hello, World!</h1>
  <p>This is an ExpressPlus webpage.</p>
  `, 'My App', options);
});

Static Files

exp.static('folder');

Restricting Access

exp.restrict("*", function (req) => {
	if (req.ip = "blacklisted ip") {
		return 'Your IP was banned!'; // display this instead of the page
  }else{
 		return true; // display the actual page
  }
});

Ratelimiting

When creating an ExpressPlus instance, the constructor has an extra parameter for ratelimiting.

const exp = new ExpressPlus(3000, 20);

As you can see above, there is a new parameter with the value of 20. This is the number of requests that can be made on a page in 60 seconds. If not defined, it will be automatically set to 100.