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

@eviltik/devsrv

v1.5.2

Published

Nodejs http(s) server for web development with some cool features.

Downloads

11

Readme

devsrv

A nodejs http(s) server for web development with some cool features.

Motivation

How many days to test all standalone webservers npm module with all simple features i'm looking for, vs time to code it. I coded it.

Command Line Usage

You can use devsrv as a standalone webserver.

Install

$ npm install -g devsrv

Run

Go into the directory you want to serve (having an index.html file), then just type

$ devsrv
config: use config file [...]
server: start listening on 192.168.1.36:8443
server: ready

Options

$ devsrv
Usage: devsrv [options]

Instant self signed certificate https web server for developer.

Options:
  -V, --version                         output the version number
  -d, --document-root <documentRoot>    DocumentRoot (default: "./")
  -a, --access-log                      Enable access Log
  -e, --explorer                        Directory listing (default: false)
  -l, --listening-port <listeningPort>  Listening port (default: 8443)
  -i, --interface <interfaceRegexp>     Network interface filter (regular expression)
  -o, --open-browser                    Open the browser (default: false)
  -m, --monitor-changes                 Monitor file changes and reload webpage (default: false)
  -c, --config-file <configFile>        Configuration file (default: "./devsrv.config.js")
  -b, --build                           trigger build process (default: false)
  --build-dst <buildDst>                build dist directory (default: "./dist/1.0.0/")
  --build-src <buildSrc>                build src directory (default: "./public")
  -h, --help                            display help for command

Optional config file

When starting, the process try to read ./.devsrv.js in the current directory or in specified --config-file directory config option.

Programmatical usage (nodejs)

You can use devsrv programmatically.

Install

$ npm install devsrv

Minimal js code

const Server = require( 'devsrv' );
const serverInstance = new Server();
serverInstance.start();

With a config object

const Server = require( 'devsrv' );

const config = {

    documentRoot: './',
    listeningPort: 8443,
    regexpInterface: /wi-fi|eth0/i,
    browser: true,
    //features:{
    // see #Features
    //}
};

const serverInstance = new Server( config );

serverInstance.start();

Features config

You can specify theses options if the config object.

const config = {
    documentRoot: './tests',
    interfaceRegexp: /wi-fi|eth0/i,
    openBrowser: true,
    clientRedirects:[
        {
            urlSrc:'/',
            redirectTo:'/tests/index.html'
        }
    ],
    urlRewrites: [
        {
            urlSrcRegexp:/^\/tests2/,
            replaceWith:'/tests'
        }
    ],
    textReplacements: [
        {
            queryVar:'r',
            queryVarRegexp:/^0\.[0-9]{3}$/,
            replaceRegexp:/THREEJSVERSION/g,
            defaultValue:'0.119',
            pathRegexp:/\.(html|js)|(\/)$/
        }
    ],
    monitorOptions:{
        enable:false,
        directories:[ './' ],
        fileRegexp:/\.(html|jsm?)$/,
        excludeRegexp: /node_modules/
    }
};

module.exports = config;

Use with npm

npm install devsrv then add start script in your package.json

  "scripts": {
    "start": "node node_modules/devsrv/bin/devsrv.js -d ."
  },

then

$ npm start
config: use config file [...]
server: start listening on [...]
server: ready

Build process

devsrv -b will trigger build process. You can add this in devsrv.config.js:

"buildOptions": {
        "src":"./tests",
        "dst":"./dist/v1.0.0/threejs.119",
        "replaceRegexp":"THREEJSVERSION",
        "defaultValue":"0.119",
        "fileRegexp":"\\.(html|js)$"
    }
  • remove dst directory if already exists
  • copy files from src directory into dst directory (recursive),
  • find files match regexp fileRegexp, then replace string in file using replaceRegexp with value defaultValue

Monitor changes

devsrv -m will monitor documentRoot recursively and we send an event to the browser each time a file or directory has changed. The browser use a SSE client to receive the event.

Under the wood, fs.watch is used. In tests/index.html you will find the peace of code to use to handle Server Side Event Events ("reload" event only).

monitorOptions:{
    enable:false,
    directories:[ './' ],
    fileRegexp:/\.(html|jsm?)$/,
    excludeRegexp: /node_modules/
}

Debugging

Set env var DEBUG with any value i.e DEBUG=* devsrv.

Changelog

v1.0.0 - 02/18/2022

  • [x] Add: use HTTPS with generated self signed SSL certificates by default
  • [x] Add: client redirects handler
  • [x] Add: url rewriting handler (proxy)
  • [x] Add: static content webserver with content rewriting
  • [x] Add: open web browser option

v1.1.0 - 02/18/2022

  • [x] Add: static webserver with content rewriting using query string variable

v1.3.0 - 02/18/2022

  • [x] Add: detect Codesandbox, then use http rather than https, because of Codesandbox reverse proxy ssl termination

v1.3.1 - 02/21/2022

  • [x] Change: code refactor
  • [x] Change: change config file name
  • [x] Add: explorer (directory listing)
  • [x] Add: npm build script (releases static files, serverless provider compliant i.e vercel )

v1.4.0 - 02/23/2022

  • [x] Add: monitor file changes and reload web page, no websocket but Server Side Events (SSE)
  • [x] Add: simple access log

v1.4.1 - 02/23/2022

  • [x] Fix: check config before start monitoring file changes
  • [x] Add: simple access log

v1.4.2 - 02/24/2022

  • [x] Fix: use session to store query var value

v1.5.0 - 03/01/2022

  • [x] Add: monitor options, see #1
  • [x] Add: js config file, see #2

v1.5.1 - 03/02/2022

  • [x] Fix package version pb

v1.5.1 - 03/02/2022

  • [x] More delay for file changes

Roadmap

  • [ ] CI tests
  • [ ] Network level throttling (simulate slow network for testing) ?
  • [ ] Systemd template ?
  • [ ] Websocket proxy ?
  • [ ] WebRTC ?