Tuesday, March 14

NodeJS Static Web Server


Introduction

The minimum amount of code to have NodeJS serve a static website.



Requirements

This code uses NodeJS module "express" which you install with the following command:
npm install express


Source Code

var Express = require('express')

  , app = Express()
 , http = require('http').Server( app )

 , htmlFolder = __dirname + '/html'
 , port = 2017
 ;

app.use(  Express.static( htmlFolder ) );


http.listen( port, function() {
 console.log( 'listening on *: ' + port );
 console.log( 'serving: ' + htmlFolder )
});


0 comments :

Post a Comment