Building Your First Node.js Express Server: A 'Hello World!' Tutorial

Here we will see how make a simple "Hello world!" program using node js 

Code :

#1. server.js
var express = require('express');
var app = express();

app.get('/', function (req, res) {
  res.status(200).send('Hello World!');
});

var port = process.env.PORT || 3000;

var server = app.listen(port, function() {
  console.log('Express server listening on port ' + port);
});


Steps to see the output of Program:

open cmd run server.js
"node server.js"
log:Express server listening on port 3000

& then

open link "http://localhost:3000/" in your browser and show result.

So, If you are having any query and doubt regarding this program then you can ask in comments. Thank You !!!
 

No comments:

Post a Comment

If you have any doubts regarding the post. Please let me know.