Creating Node.js Server
Hello Everyone,
Today I will be talking about creating a server with Node.js. The rising popularity of JavaScript has brought a lot of changes in web development. We can run Javascript on the server-side, as well as in the browser. Node is open-source and completely free. Using Node we can build back end services such as API (APPLICATION PROGRAM INTERFACE), which powers the front end (client-side). Node is easy to get started as well as building fast and highly scalable applications.
Let us get started with that.
First, download and install Node → https://nodejs.org/en/
To insure if Node was installed successfully,
go to terminal and write node -v, If you v11.0.0 or similar
that means node was installed successfully
Now that we have installed Node.js, open your text editor and create a file called example.js or whatever you want to call, must have .js extension.
- Inside the example.js, in order to create our server, we have to require a library called http.
- Next, we need to create a variable for our port.
3. Creating server, make a const of nodeServer (see the image below)
Finally, let's finish the nodeServer on line 4 at the moment its empty, the user will not get any response.
We are all done lets start are server by going to the terminal
node and the filename.js → node example.js
if you want to end the server simply write control + c.
There you have it. I hope you found this blog helpful. If you’re having any difficulty or need more explanation, I’m more than happy to help you. Please connect with me on LinkedIn or my email is singhamritpal49@gmail.com.
Happy Coding :)
Reference: