Node.js Web Apps With Express Hello World


Example

Here we create a basic hello world server using Express. Routes:

  • '/'
  • '/wiki'

And for rest will give "404" , i.e. page not found.

'use strict';

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

var app = require('express')();
    app.listen(port);

app.get('/',(req,res)=>res.send('HelloWorld!'));
app.get('/wiki',(req,res)=>res.send('This is wiki page.'));
app.use((req,res)=>res.send('404-PageNotFound'));

Note: We have put 404 route as the last route as Express stacks routes in order and processes them for each request sequentially.