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

express-vanilla

v0.5.3

Published

A vanilla express server which uses helmet, supports CORS in dev, and rotates logs daily

Downloads

6

Readme

Quick Start

This is a standard expressjs server. By defaul it serves on all interfaces and on port 3000.

npm i express-vanilla

Create an index.js file:

const initialiseServer = require('express-vanilla')

// this argument is optional, you can pass null or omit it altogether.
const options = {
  // alternative to process.env.PORT, default assumes docker deployment
  port: '3000', 
  // alternative to process.env.HOST, default mounts to all interfaces
  host: '0.0.0.0',
  // An optional mount path for serving static files. Any requests for 
  // assets will be served from ./public such that 
  // https://server/mountpath/index.html 
  // will resolve to ./public/index.html etc 
  mountpath: '', 
  // optional name to include in log messages
  serverName: 'Express Vanilla'
  bodyParserOpts: {
    // true - to enable body parsing. False to disable 
    enable: true, 
    // if enable=true, limit size of body e.g. 1kb, 1mb. Will error if 
    // limit exceeded. Default is no limit
    limit: /no limit/   
  },
  morganOpts: {},
  // do not allow empty bodies in PUT, POST, and PATCH HTTP methods
  disallowEmptyBody: 'false' 
}

const routes = [
  middleware1,
  middleware2,
  routes1,
  routes2,
]

const server = initialiseServer(options, routes)

Details

It assumes that static content resolves to the ./public folder. i.e. http://hostname:port/index.html would resolve to ./index.html

You can configure the interface and port with the following env vars:

PORT=3001
HOST=10.19.0.1

Using this server with TLS

Google and Chrome are beginning to score non-TLS sites lower and warning of insecure access. This is primarily why the default port is not 80. The choice of port 3000 is informed by Docker microservices where one or two ports exposed is sufficient and 3000 is usually the service endpoint.

I suggest implementing a reverse proxy to provide SSL termination. Nginx works well, is easy to set up and maintain, and is performant. It is suitable for most cases where traffic is reasonable (don't know exact figures - I would expect a setup to cope fine for 300 requests per minute). Any higher loads should be possible to resolve with a load balancer and additional servers.

The middleware and routers will be applied to the server in the order they have been added into the array.

The initialiser returns the express listener which you can attached event handlers to and request a graceful shutdown, etc.

Default request handlers

It implements an 404 handler for routes which aren't found. If you are creating an SPA, you may prefer to return a default page by appending a router which lists .get('*', {function}) as one of its routers.

It implements a standard error handler. You can override it by adding an alternative in the last array element