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

dev-express-static-server

v1.1.0

Published

A simple static server for developement using Express JS

Downloads

13

Readme

dev-express-static-server

A simple static server for development mode using Express JS


Note:

  • This utility's purpose is to be used in your local development environments. So some common production standards are ignored.
  • By default site-index, cors, compression (gzip) is enabled

1. Installation

npm install --global dev-express-static-server

2. Usage (command-line)

2.1. startup a server instance

dev-express-static-server <options>

Options ( <options> )

  1. --port=<port> ( default = 8080 )
  2. --dir=<path-to-directory-to-server> ( default = {CWD} )
  3. --https=<true/false> [optional] ( default = false )
    • You can also just specify --https to set it as true
  4. If --https enabled, --keyPath=<path-to-key.pem-file> [optional] ( default = "{CWD}/key.pem" )
  5. If --https enabled, --certPath=<path-to-cert.pem-file> [optional] ( default = "{CWD}/cert.pem" )

E.g.

dev-express-static-server --port=9092 --https --keyPath="~/dev-certs/key.pem" --certPath="~/dev-certs/cert.pem"

Note:

  • {CWD} is current directory where the command/util is running from
  • All paths above support HOME dir shortcut char ~
  • Temporary PID files will be managed by the script on the current dir to manage servers, if started in background.

2.2. shutdown a server instance

dev-express-static-server --stop --port=<port>

E.g.

dev-express-static-server --stop --port=9092

Note:

  • --port option is mandatory as PID files will be created using port numbers as ID and using that we will shutdown node process.

3. Usage (api)

let server = require("dev-express-static-server/server.js");

3.1. server.start(port, [directory, opts]) method

Arguments:
  • port is required argument

  • directory - Directory to serve ( default = {CWD} )

  • opts

    • opts.useHttps - If true, https server instance will be created, otherwise http will be used
    • opts.keyPath - If https enabled, path to key.pem file ( default = {CWD}/key.pem )
    • opts.certPath - If https enabled, path to cert.pem file ( default = {CWD}/cert.pem )
    • opts.onListen - [callback] function which will be invoked once the server starts up successfully and is listening for clients. An object argument with { pid: process.pid } will be passed to the callback.
        opts = {
            onListen: function (args) {
                console.log(args.pid);
            }
        }
    • opts.onError - [callback] function which will be invoked in case any error happens in server startup. The thrown error will be passed to the callback.
        opts = {
            onError: function (err) {
                console.log(err.message);
            }
        }
    • opts.onClose - [callback] function which will be invoked once the server is stopped.
        opts = {
            onClose: function () {
                console.log("Cleanup !");
            }
        }
Returns:
  • Returns an object with close method, which if called shuts down the server
let serverInstance = server.start(9092, path.resolve("../app/", {
    https: true,
    keyPath: path.join("../../dev-certs/key.pem"),
    certPath: path.join("../../dev-certs/cert.pem"),
    onListen: ...,
    onClose: ...,
    onError: ...
}) );

// After job done ..
serverInstance.close();

3.2. server.kill(processID) method

You can also kill your server if running in a separate processs and you know its process ID.

Note:

  • Be careful to not kill your current process
Arguments:
  • processID is required argument

E.g.

server.kill(9879869);