Beginner: How to create a backend Node.js server using MongoDB
We will create a mini backed Node.js server that uses a MongoDB.

First we setup our package.json file and include all the dependencies we need.

Now, we create our server.js file, the application will start from this js file. We are going to use the express framework for simplicity and CORS to handle the HTTP requests.

We now create our controller file. The controller file will be the interface from our server.js to our service file which contains the methods of putting and retrieving data from our MongoDB

Going to the data.service.js, this file will contain mongoose function in putting and retrieving data from our MongoDB.

Now we have to create our db.js file that will connect to our application to the database.

You will notice in our db.js file that we required a ‘config.json’ file, this file will contain the connection string that leads us to our database.

Now we will create our data.model.js file, this will be the basis of our database schema for the data.

Lastly, we will create our error-handler.js file that will handle any error in the server application and return it.

Let’s take a look of the file structure before move on.

Using NPM, we just have to run the command <npm install> in the project directory using the terminal. To run our server we have to input <npm start> and our backend server is ready to go. Below is a demonstration that our code is working. I will do another post for the front-end application in the near future.
Link for front-end tutorial https://medium.com/@kimtee92/basic-create-an-angular-4-web-app-and-use-http-client-module-f29bf4b4e22



Github link: https://github.com/kimtee92/nodebackend.git