node-paperboy: A node.js module for delivering static files

There’s definitely no shortage of new Node.js projects these days. From @felixge, node-paperboy let’s you serve up static pages in your Node.js app.


  sys = require('sys'),
  path = require('path'),
  http = require('http'),
  paperboy = require('../lib/paperboy'),

  PORT = 8003,
  WEBROOT = path.join(path.dirname(__filename), 'webroot');

http.createServer(function(req, res) {
    .deliver(WEBROOT, req, res)
    .before(function() {
      sys.puts('About to deliver: '+req.url);
    .after(function() {
      sys.puts('Delivered: '+req.url);
    .error(function() {
      sys.puts('Error delivering: '+req.url);
    .otherwise(function() {
      res.sendHeader(404, {'Content-Type': 'text/plain'});
      res.sendBody('Sorry, no paper this morning!');

[Source on GitHub]

News Films

Our little film studio focuses on telling developer-centric stories that need to be seen.

GopherCon 2016 Conference Recap

0:00 / 0:00