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 🙏

© 2025 – Pkg Stats / Ryan Hefner

sea-d45-framework

v0.1.0

Published

a library for creating http servers

Readme

Framework is a package for making http routing easier. It currently has full functionality for http server creation, get requests, and handling http, css, and plain text responses.

lib/router.js is responsible for keeping track of the routes once they are created. The module exports a constructor function, which will create a new router object. The router object has a property .routes, which contains the following:

'GET': {}, 'POST': {}, 'PUT': {}, 'PATCH': {}, 'DELETE': {}

Each of these empty objects will store the routing information for that call.

The router has a method for each type of call that will add a route to the object. For example:

Router.prototype.get = function(route, cb) { this.routes['GET'][route] = cb; };

The router also has a 404 method, which will return the status 404 and write 'not found' to the client.

Router.prototype.route is a function which is called when the http server runs its listener function. It takes two parameters, req and res, which are fed to it by the server. The function:

Router.prototype.route = function(req, res) { (this.routes[req.method][req.url] || this.fourOhFour)(req, res); };

This looks up the callback function stored in the routes object for whatever request is being made. If the route does not exist, the function runs the 404 method.

In lib/app.js, an http server is created with the App.prototype.listen method.

App.prototype.listen = function(port) {

var server = http.createServer(function(req, res) { router.route(req, res); });

server.listen(port, function() { console.log('server running on port ' + port); }); };

Once the server is created on the user-specified port, it will print to the console that the server is up and running. When a request is made, the request listener function calls router.route. router.route checks if there is a route with that url for that request method, and if it exists it returns the callback function defined by the call to router.get (or the equivalent method for the other types of requests).

In app.js, there is a function App.prototype.makeRoute. makeRoute takes three parameters, a route, a request method, and the desired response data. It uses the request method (reqMethod) to call the corresponding function on the router object and define a callback function for when the request is made.

The callback function currently works with GET requests but could be expanded to handle each type of request. Currently this module automatically checks if the response is going to be of content-type 'text/html' or 'text/css', and if not it will default to 'text/plain'. It then writes a status of 200 and the content type to the header, and writes the response data to the client. If the response data is a path to an HTML or CSS file, makeRoute will read the file and pass it into res.write.

This module only has full support for HTML, CSS, and plain text but could easily be expanded to support many types of content and different requests.

When when creating a new instance of the framework, you may specify a public folder for serving static files:

var app = new Framework(__dirname + '/public');

To send responses, you can use the app.sendRes functionality:

app.sendRes(req, res, message);

If a message is entered, the message is sent as the response.

If no message is entered, the file corresponding to the url is found in the public folder and sent as a response. Example:

var app = new Framework(__dirname + '/public');

app.get('/index.html', function(req, res) { app.sendRes(req, res); // sends file 'index.html' from public folder });

An example usage of the framework:

var Framework = require('sea-d45-framework'); var app = new Framework(__dirname + '/public');

// set get route for '/' app.get('/', function(req, res) { // your code goes here });

// set post route for '/greet' app.post('/greet', function(req, res) { // your code goes here });

// set route for get request to '/index' // will send file from path specified in third argument app.makeRoute('/index', 'get', 'public/index.html');

// start server listening on port 3000 app.listen(3000);

This project makes use of sea-d45-router: https://github.com/codefellows/sea-d45-router.