Basic Node.js application

const express = require('express');
const app = express();
app.listen(8000, function () {
  console.log('Server listening on port 8000');
});
app.get('/',serverResponse);
function serverResponse(req,res) {
  res.send('Hello, this is a message from the server');
}
  • Use of express.js module: Efficient server development

Running node.js

  • - Install express.j module (only once)
npm install express
  • - Run the local server
node server.js
  • - Open the browser at the url http://localhost:8000

Hosting node.js project on a server

  • - Warning: Node.js project requires dedicated machine
    • Usually not compatible with shared hosting
  • - Solution: Self-hosting, Virtual Private Server (VPS)
28/38