Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aquasmit/547a714a1337d0e1743edeaa51af7047 to your computer and use it in GitHub Desktop.
Save aquasmit/547a714a1337d0e1743edeaa51af7047 to your computer and use it in GitHub Desktop.
Node.js as simple web server

###Using node.js as a simple web server that will serve static files

You can use Connect and ServeStatic with Node.js for this:

Step 1: Install connect & serve-static packages npm install connect serve-static

Step 2: Create server.js file with content

var connect = require('connect');
var app = connect();
var serveStatic = require('serve-static');

app.use(
    serveStatic(__dirname)
).listen(8080,function(){
    console.log('Server running on 8080...');
});

Step 3: Spin up server.js $ node server.js

You can go to http://localhost:8080/yourfile.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment