This article is written to show a specific purpose which is to show how to make a string “Hello World!”, normally a word which is usually taken to test a simple output can be presented in any normal programming language used. In the context of this article, it is using a Javascript which is executed in NodeJS as a tools which is taking a role as a Server-side Javascript render processing entity. The steps are simple where the base folder for this purpose can be taken from the one generated using express framework. The reference for generating a folder that is actually a web-based application powered by express framework can be taken from the article titled ‘How to Create an Express Web-based Framework Application to be deployed in Node.js’ in this link. Below are steps taken after having the folder mentioned before generated :
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 :