Monday, 6 March 2017

How to setup node in Windows and create application ?


  • Download NodeJS application and install it.
    It will setup all the required environment variables of NodeJS.
  • Check NodeJS installation
    > node --version
  • Check npm installation
    > npm --version
  • Create a project directory and install module express
    > mkdir test> cd test
    > npm install express

  • Create an Application JS file testserver.jsvar express = require ('express');
    var app = express();
    app.use(express.static(__dirname));

    app.get('/hello', function(request, response) {       
       response.send("Hello Node");
    })

    app.get('/bye', function(request, response) {       
       response.sendFile(__dirname + '/bye.html');
    })

    app.listen(8080, function(){
        console.log("Server started on 8080");
    })
  • Start Node server> cd test
    > node testserver
  • Run and test application
    http://localhost:8080/hello

    http://localhost:8080/bye

No comments:

Post a Comment

Note: only a member of this blog may post a comment.