Tuesday 26 February 2019

Express: app.get(path, callback [, callback ...]): Process get request

app.get(path, callback [, callback ...])
Routes HTTP GET requests to the specified path with the specified callback functions.

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

app.get('/welcome', function (req, res) {
  res.send('Hey user!!! Good Morning....:)');
});

index.js
var express = require('express')

var app = express()

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

app.get('/welcome', function (req, res) {
  res.send('Hey user!!! Good Morning....:)');
});

app.listen(3000, () => {console.log("Application started in port 3000")});

Run index.js.


Open the url ‘http://localhost:3000/’.

Open the url ‘localhost:3000/welcome’.


Previous                                                 Next                                                 Home

No comments:

Post a Comment