Hello programmers welcome to Coderzway today I am going to show you how to start a node server. If you want to learn backend development with node js and you want to create your first node server than you are at the right place.
Today I will show you how to create a basic node server. So inorder to start a node server you need to install one software and follow couple of steps it is going to be quick so lets start our own server.
Want to become a backend developer than read this article – roadmap to become a backend developer. This guide will help you to become a successful backend developer.
How to start a node server
To start a node server you need to go through a couple of steps. I will tell you step by step how to start a node server so read carefully. Don’t worry if you don’t have node js experience this is a step by step guide on how to start a node js server.
1 – Install Node js on your machine
It is very easy to install go the node js official download page and download the LTS version currently available according to your system. To download node js go here – Download Node JS
After downloading go start the installer and just click on next and finish the setup. After that to check wheather node is installed go to your terminal and type node -v this will show you your current node version which means you have successfully installed node on your machine.
2 – Create a folder and file
Now node is installed create a folder wherever you want and create a file name server.js inside the folder you can name it anything I will be using vs code to edit the code. You can use any code editor you want.
3 – Npm init
After creating files and folder open a terminal or command prompt in your file location and type npm init in your terminal this will initialize a the node app.
4 – Install express
After npm init you need to install express node library which is a small library for creating servers and routes it is used in every node app.
So to install express go to the terminal in your file location and type npm install express this will install express library in your project you will see all your installed libraries in package.json file.
Want to know more about the best node js libraries than read this guide – Best node js libraries to use. I have talked about the best node js libraries.
5 – Paste the following code
After installing express you are good to go now paste the following code in the server.js file and type node server.js in the terminal of your file location you should be seeing server started message in your console congrats for your first server
const express = require('express') const server = express() server.listen(5500, () => console.log('SERVER STARTED'))
Congratulations on your first node server This was just a starting the server in future you will be learning more about node api and routing good luck for your journey.
I hope you found this guide useful and helpful. If you want more articles like this do subscribe to our coding newsletter for updates of our latest articles and comment down “I did it” if you started your first node server It is very simple and easy.
Thank you for reading Have a nice day 🙂