Tuesday, July 24, 2018

Simple HTTP server on Node JS

Ever needed an HTTP server just to test out something. If you are working on Node platform then you can do so very easily by following the mentioned steps.


1. Simply paste below mentioned code in a file server.js
var connect = require('connect');
var serveStatic = require('serve-static');
connect().use(serveStatic(__dirname)).listen(8080, function(){
    console.log('Server running on 8080...');
}); 

2. Run this server.js via command prompt
node server.js

3. This will start a HTTP server on port 8080 and pickup the content from current directory

 This is quite useful when you want to see some static content using a server

No comments:

Post a Comment