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

static-now

v0.3.0

Published

The fast track to serve up static files

Downloads

4

Readme

static-now

"But I just want so serve up some files... why all of this setup". Have you ever said that to yourself.

Worry no more - static-now is here to help you. With a single line your web server is ready to roll, and you can focus on the static files instead.

require("static-now")();

This will start a Koa web server on port 3000 and start listening.

You can do it on two lines also for readability

var staticnow = require("static-now");
staticnow();

Starting the application

Koa uses generators from ES6 and require 0.11.9 or higher (actually higher... go 0.11.16 for now). You can run multiple versions of node by using n or nvm.

Start you application with the harmony features enabled:

node --harmony app.js

Or if you're using io.js leave out the flag:

node app.js

Here's a package.json node ready for you so that you can use npm start:

"scripts": {
	"start": "node --harmony app.js"
}

Configuration

There's just a few configuration options that you can use to control the behaviour of static-now.

Directory

var options = { directory : __dirname };
require("static-now")(options);

By default the directory that node is started in is used. Meaning if you go npm --harmony app.js in /Volumes/Users/marcus/demo the files in that directory will be exposed via the web server.

Port

var options = { portnumber : 3456 };
require("static-now")(options);

By default port 3000 is used, meaning that your web server is started at http://localhost:3000.

For hosting in Heroku, or other platform as a service providers, you can use a process parameter to get the correct port. Like so:

var options = { portnumber : process.env.PORT };
require("static-now")(options);

Autostart

var options = { autostart : false };
var app = require("static-now")(options);

You don't have to start the application right away, if you don't have too. The static-now function returns the Koa application so that you can start it yourself, when appropriate.

A good time when this can be handy is for testing, when usually the testing framework is starting the application up. Like this, using supertest

var supertest = require('supertest');
var staticNow = require('static-now');

describe('Starting app via supertest', function () {
	it('here is how', function (done) {

		var options = { autostart : false };
		var app = staticNow(options);

		// Let supertest start listening
		var request = supertest.agent(app.listen());
		request
			.get('/README.md')
			.expect(200)
			.end(done);
	});
});

Log message

var options = { log : true };
var app = require("static-now")(options);

static-now spits out some log messages showing you the current configuration etc. You can turn that off or on using the log option.

LICENSE

The MIT License