Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yakovkhalinsky/node-static

A simple to implement static file server for node.js
https://github.com/yakovkhalinsky/node-static

Last synced: 1 day ago
JSON representation

A simple to implement static file server for node.js

Awesome Lists containing this project

README

        

node-static
===========

A simple to implement static file server for node.js

Example
===========

var http = require("http");

var static = require("./lib/static.js");

// An example custom function to deal with 404's returned by the static module
// You could use this to either provide a custom 404 or just fallback to other routes
function notFoundErrors(req, res, code, message) {
console.log('running callback for not found errors:');
console.log(code + ': ' + message);
res.writeHead(code);
res.end(message);
return;
}

// initialise the static file server
static.init({
basePath : './public', // required
pathMatch : [ '/img', '/css', '/js', '/html' ], //optional
errorMessage : '404 Not Found', //optional
errorCallback : notFoundErrors, //optional
logging : true // otpional
});

http.createServer(function (req, res) {
static.serve(req, res); // attempt to serve the static files
}).listen(1337);