Thursday, July 13, 2017

16/06/2017

ExpressJS – Hello World


💙Create a new file called index.js and type the following in it.
             var express = require('express');
             var app = express();
             app.get('/', function(req, res){
             res.send("Hello world!");
            });
            app.listen(3000);

💙Save the file, go to your terminal and type the following.
           nodemon index.js

💙Go to http://localhost:3000 and a message will be displayed as in the following screenshot.
     
       


    How the App Works?

💙app.get(route, callback)
          This function tells what to do when a get request at the given route is called. The callback function has 2 parameters, request(req) and response(res).

💙res.send()
          Here we are sending the string "Hello World!".

No comments:

Post a Comment

HTML introduction

HTML stands for Hyper Text Markup Language. HTML describes the structure of web page using markup. HTML elements are the building blo...