1. Create a new file named app.js which can be precedented by renaming the old app.js file into app.original.js or any other name which can be identified.
2. Edit the file and add the following snippet code. It means, the new file named app.js started with an empty content and then just fill the file with the following content :
const express = require('express') const app = express() app.get('/', (request, response) => response.send('Hello World !')) app.listen(3000, () => console.log('app is listening in port 3000'))
Roughly explaining, the main point is using the express framework and then the definition of accessing the service where the URL root address will return a string ‘Hello World !’ printed in the page. The end line is simply stating that the application will listen the request in port 3000 and it will print in the console after executing the application as shown in the next step.
3. Just save the file with the above snippet code inserted into the file named app.js and then run the file using the following command :
user@hostname:~/nodejs/test$ node app.js app is listening in port 3000
The following is the output of the response given by NodeJS after requesting it via web browser :