Member-only story
Learn MongoDB & Express By Building A REST API Service
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.

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

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:
- Change the
"main": "index.js"
to"main": "server.js"
. - Add a Bash script called
start
to it.
"scripts": {
"start": "nodemon server.js"
}