In this Post you will learn how to setup a Backend Express Js server.
- We will first start by creating a directory for our backend server using command and then initiate npm project in that directory.
mkdir -p ~/Backend/"3.5 Secrets Project" //Create a Backend directory
cd ~/Backend/"3.5 Secrets Project" //Navigate to Backend directory.
touch index.js //create a index.js file in the Backend directory.
npm init //this will create a package.json file in the Backend directory.
npm install express //this will install express js and all the required dependencies.
- 2. Now we will edit the package.json file switch our project to use Modules of JavaScript ES6 update. Add this line to switch to modules type.
"type" : "module";
- 3. We need to install nodemon module which will be usefull to keep our Backend server running and update automatically whenever we make changes in our code.
sudo npm install nodemon -g //-g will globally install on the machine.
- 4, Next using Visual Studio Code editor we will edit our Project files. First we will edit index.js file and add some basic code to start our server.
- 5. Start the server by using nodemon command.
nodemon index.js
Now If there are no mistakes your backend server should be online and running and Terminal output will look like this.
This is the log of port number used in this project.