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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cre-nodejs-server

v2.0.0

Published

node.js server

Readme

cre-nodejs-server

Simple web server, based on express and socket.io.

example index.js

var server = require('cre-nodejs-server');

server.start({
  rootDirectory: require('path').resolve(__dirname), 
  routes: [
    { route: '/myPage', handler: server.clientFileHandler('./Client/myPage.html') },
    { route: '/myCustomHandlerPage', handler: require('./customHandler') }, 
    { route: '/myOwnClientDir/*', handler: clientFileHandler() }, 
  ]
  sockets:['socketPath1', 'socketPath1']
  pageHeader: 'html/header.html'
});

parameters for start method:

port

rootDirectory

Where we will be lookig for files. Can often use require('path').resolve(__dirname) to use the same dir as index.js runs in.

tempFolder

Directory used for routes starting with /temp/, typically a writable location, for file upload. Default is C:/tmp

routes

Array of route objects. For each term:

  • route: string defining the route, use * as wildcard
  • handler: must be a function(request, response)

sockets

List of socket paths that will be initialized at server start. This makes sure the socket is created before any client tries to connect. This is not necessary if we expect the server to start sending before any client connects.

pageHeader

File that will be included in the head section of all html files.

contentTypes

Mapping between file extensions and content-types, in case something is missing in the default list.

Standard route handlers

clientFileHandler()

{ route: '/myOwnClientDir/*', handler: clientFileHandler() }

All files under myOwnClientDir will be handled as client/content files and downloaded.

clientFileHandler(filePath)

{ route: '/myPage', handler: server.clientFileHandler('./Client/myPage.html') }

Defines an alias: http://server/myPage will be the same as http://server/Client/myPage.html

Default handlers

These handlers are defined by default:

{ route: '*/Client/*', handler: clientFileHandler()}
{ route: '/temp/*', handler: clientFileHandler() }
{ route: '/', handler: clientFileHandler('./Client/index.html') }
{ route: '*', handler: require("./pageNotFoundHandler") }

Your own routes will come before those, except an override for "*", which will always be handled last, but before the default one.

Sockets

Just call server.socket(socketPath) to get a socket.io socket. This creates the socket if it does not exists yet and returns it.

A custom handler for the socket can be defines by creating a module with the specified path. The module must return a function(socket), that is be called on socket connection.

Events

server.events is an EventHandler.

serverSarted is fired when the start process is completed.

Examples

See included examples for more information.