Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Nodejs static web server boilerplate
.DS_Store
node_modules/

A simple static nodejs server boilerplate

Use this gist to get started with a dead simple, nodejs static web server.

Getting started

To get started, install the required node modules:

npm install

Then issue the following command to run the server:

npm start

Navigate to http://localhost:8080/ and files from the public folder will start being served.

var static = require('node-static');
var publicfiles = new (static.Server)('./public');
require('http').createServer(function (request, response) {
request.addListener('end', function () {
publicfiles.serve(request, response);
});
}).listen(8080);
console.log('Navigate to http://localhost:8080/.');
<!DOCTYPE HTML>
<html>
<head>
<title>Simple static nodejs server boilerplate</title>
<meta charset="utf-8">
</head>
<body>
<h1>A simple static nodejs server boilerplate</h1>
<p>Use this gist to get started with a dead simple nodejs static web server.</p>
</body>
</html>
{
"name": "nodejs-static-file-server-boilerplate",
"version": "0.0.1",
"description": "A simple boilerplate to easily get started with a nodejs static file server.",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"node-static": "0.6.x"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment