CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Follow publication

Learn MongoDB & Express By Building A REST API Service

Dr. Ashish Bamania
CodeX
Published in
8 min readJul 6, 2022

Let’s learn to make an API for our Ice-cream company using MongoDB and Express!

What is Express?

Express.js / Express is a back-end web application framework for Node.js.

Express.JS Logo

What is MongoDB?

MongoDB is a scalable cloud-based no-SQL document database.

MongoDB Banner

Initialising Our Project

Using Bash, let’s make a folder called icecream-api and change the directory to it.

$ mkdir icecream-api$ cd icecream-api

Let’s initialise a package.json file that will contain all the dependencies for the project. We will use yarn for this.

$ yarn init --yes //This will automatically answer yes to all questions during initialisation

Next, we will install the following dependencies to our project.

  • express
  • cors
  • mongoose
  • @mongoosejs/double
  • dotenv
$ yarn add express cors mongoose @mongoosejs/double dotenv 

We will add nodemon as a development dependency to our project.

$ yarn add nodemon --dev

Your package.json file will look like this:

{
"name": "icecream-api",
"version": "1.0.0",
"main": "index.js", <--Change this to "main":"server.js"
"license": "MIT",
"dependencies": {
"@mongoosejs/double": "^0.2.0",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"mongoose": "^6.4.3"
},
"devDependencies": {
"nodemon": "^2.0.19"
} <-- Add 'scripts' here
}

Make the following changes to it:

  1. Change the "main": "index.js" to "main": "server.js".
  2. Add a Bash script called start to it.
"scripts": {
"start": "nodemon server.js"
}

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

CodeX
CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Dr. Ashish Bamania
Dr. Ashish Bamania

Written by Dr. Ashish Bamania

🍰 I simplify the latest advances in AI, Quantum Computing & Software Engineering for you | 📰 Subscribe to my newsletter here: https://intoai.pub

No responses yet

Write a response