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

asimov-server

v1.5.0

Published

High performance static server cluster plugin for asimov.js

Downloads

25

Readme

asimov-server

NPM version Build Status Code Climate Dependency Status

A high performance static server cluster plugin for asimov.js

Made by Adam Renklint, Berlin 2014. MIT licensed.

asimov-server is a high-performance static server based on express.js. It uses a cluster of workers to serve a static site, built with asimov-pages or any other way, and allows you to customize the request/response flow with super-charged express.js middleware.

Getting started

First things first - create a new, basic project. Then install asimov-server from npm.

$ npm install --save asimov-server

To use the server plugin, add it in your app's plugin hook, in index.js and start your app with asimov or node index.js.

var asimov = require('asimov');
var server = require('asimov-server');

// Keeping all our setup in this format allows our
// app to be used as a plugin by other projects
module.exports = function plugin (options) {
  asimov.use(server);
};

// The project bootstrap, using our app as a plugin
module.exports.start = function bootstrap () {
  asimov
    .use(module.exports)
    .start();
};

// If we are not loaded as a plugin, start the app
module.parent || module.exports.start();

Configuration

asimov.config({
  // the folder where the static content is located
  'server.sourceDir': 'public',
  // seconds, how often request counts are logged
  'server.logInterval': 15,
  // seconds, how often workers report request counts
  'server.workerReportInterval': 5
})

Middleware

Create or use regular express.js middleware.

// lib/middleware/myMiddleware.js
module.exports = function myMiddleware (req, res, next) {
  // do some
  next()
};

Then include and register the middleware in your project's plugin hook.

// index.js
var myMiddleware = require('./lib/middleware/myMiddleware');
module.exports = function plugin () {
  asimov.middleware(myMiddleware);
};

Pre and post middleware

Unlike in vanilla express.js app, it's possible to hook into several different steps in the request handling lifecycle.

Pre-middleware is executed before any other middleware and could be used to override the entire normal request lifecycle and middleware chain.

var overrideEverything = require('overrideEverything');
asimov.premiddleware(overrideEverything);

With post-middleware, you also hook in middleware right after the server has tried to serve content from the static source folder, if no content was found. With this you could, for example, add a custom logger to keep track of the amount of served 404s.

var myCustom404Logger = require('myCustom404Logger');
asimov.postmiddleware(myCustom404Logger);

Beware, when the pre-middleware is executed, the response will not have been equipped with any caching headers yet, so if you send a response, you might want to take of that on your own.


Develop and contribute

  1. First, fork this repo.
  2. Implement something awesome
  3. Write tests and run them with npm test
  4. Submit a pull request

Credits

Author: Adam Renklint.