My Sites


Monday, July 14, 2014

Node js Hello World using Express Framework

What is Node js Express Framework?
Express is a minimal and flexible node.js web application framework, providing a robust set of features for building single and multi-page, and hybrid web applications.

 1.)Include express dependency in package.json
 
2.) npm install



 














3.) Your Project Hierarchy will looks like as  follows.







4.)Inside app folder I have located the index.html file along with the resources  like  css,js files.
 
5.)app.js


6.)Run the application


7.)Well That's all!!!


$ npm init //To initialize the package.json
$ touch app.js // Create app.js

"use strict"; //Defines that JavaScript code should be executed in "strict mode".The "use strict" directive is new in JavaScript 1.8.5 (ECMAScript version 5).

var express = require('express');
var http = require('http');

var app = express();
app.set('port', process.env.PORT || 8081);
app.use(express.static(__dirname + '/app/'));


var server = app.listen(8081,function(){
console.log("MLP EP Config console is listening to 8081");

});

package.json

{
  "name": "MLPEPconfigConsole",
  "version": "1.0.0",
  "description": "EP Configuration and Migration API Console for Pearson MLP Newgateway",
  "main": "app.js",
  "private": true,
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Amila Iddamalgoda (amila.iddamalgoda@pearson.com)",
  "license": "ISC",
  "dependencies":{
  "express":"~4.13.1"
  }

}


No comments:

Post a Comment