- Let us create a basic node express server
- let us setup our package.json file which will keep track of all the dependencies we will be installing
- change into our server folder
cd server
- run the following code to create our package.json file
npm init -y
- we will now need to install some dependencies, run the following command
npm install express mongodb dotenv nodemon
- express is a node framework that will help us setup our server routes
- mongodb will help us connect to our MongoDB server
- dotenv will allow us to create a .env file which will be responsible for holding sensitive information
- nodemon will allow us to update our server on every save, it will make our development a lot more easier than having to reset the server on every change.
- finally, create an index.js file and write in the following code
// import express
const express = require("express");
// create an instance of express called app
const app = express();
// create a test router
app.get("/hello", (req, res) => {
res.status(200).json({ mssg: "hello" });
});
// create a port variable
const port = 5000;
// listen to our server on our localhost
app.listen(port, () => {
console.log(`Server is listening on <http://localhost>:${port}`);
})
- now let us run our server, enter the following code in your terminal
- make sure you are in the server folder
node index.js
- if you see the following console log, then you are in good shape

- now open up http://localhost:5000 in your browser and you should see Cannot GET /
- this is normal since we did set up anything at our root end point “/”
- we did set up a end point at “/hello” so go to http://localhost:5000/hello
- you should be greeted with following message, if so then our server is working as intended

2a. Creating our scripts
- it is going to be a lot convenient for us down the road if we setup some scripts to help us with starting up our server and keep track of any changes we make to our server files.