NodeJs

It is an open source server environment that could interpret and run Javascript on the server side. Node Js can be used for several kinds of operation. Some of the operations are the following

  • Generate dynamic page content
  • Create, Open, Read, Write, Delete, and close files on the server
  •  Collect form data
  • Add, Delete, Modify data in your database
  • Support the execution of tasks on certain events
  • Node.js uses asynchronous programming – meaning ready to handle the next request although the previous task is not completed. And as the previous task has a response, the server will continue to complete the task already started.

Writing a Node Js

The following example demonstrate how to create a server that is replying a simple text message. But before starting to write a Node.js, make sure that your machine has already installed Node using the node -v command. if the node is not installed in the machine, make sure to download and install Node Js from the official page https://nodejs.org/en using the most recommended options.

Figure 1.0 Checking the Node Version

The file of Node has got an extension of .Js which stands for Java Script. Let us write Js server that is returning a plain Text ‘Hello World’

Figure 1.1 Server returning a plain text ‘Hello world’

After Saving the file , the next action will be executing the .Js file which contain the server as well the message that is suppose to show. Therefore Running the server will be as follow node <fileName.js>

Figure 1.2 Running Server on the stated port

The next action is to access the server with the URL address http://localhost:8080 or typing the address on the browser will show the message Hello World

Figure 1.3 Accessing the server through Browser

Scroll to Top