Build a REST API using MongoDB, Express.js and Node.js

Lets try to make a simple REST API using MongoDB, Express.js and Node.js

You can also find the project in REST_API-MongoDB repository.

Also look at this api url https://restapi-cars.herokuapp.com
for getting data https://restapi-cars.herokuapp.com/Cars

Get Started..

"start": "nodemon server.js"

Lets install some packages

npm i express
npm i nodemon
npm i cors
npm i mongoose

Now let’s create a database in mongodb

Lets start coding again..

var Connection_url = 'mongodb+srv://Rest-API_lmas:<password>@cluster0.gklyj.mongodb.net/<dbname>?retryWrites=true&w=majority'
import mongoose from "mongoose"
mongoose.connect(Connection_url, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true
})

Mongoose allows the following schema types:

A Mongoose model is a compiled version of the schema definition that maps directly to a single document in the collection.

nodemon server.js

Let try it using Postman…

Great you have completed the REST API using MongoDB , NodeJs and ExpressJs

Now Lets try to host the application in “HEROKU”

Enjoy playing with this..

You can also find the project in REST_API-MongoDB repository.

Thanks for reading……

--

--

Full Stack Developer [Web | Mobile]

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store