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);
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