Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/yakovkhalinsky/node-static
- Owner: yakovkhalinsky
- Created: 2012-11-10T22:24:10.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2012-11-10T23:12:20.000Z (about 12 years ago)
- Last Synced: 2024-10-12T23:54:40.703Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 113 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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);