This tutorial aims to guide you to the process of building API’s using Node, Express and Mongodb.
What we are Building ?
An API for Listing Songs - User can perform CRUD operations - Create, Read, Update, Delete Songs and also the Categories/Genre the Songs belongs to.
This is the part-1 of the series (bookmark):
- Setting up and building our Express Node App (Part 1 - You are Here )
- Adding ES6 support to our App (Part 2)
- Connecting Mongodb to our App using Mongoose ( Part 3)
- Creating the Songs and Categories CRUD API
- Writing Unit Tests to test our API
So let’s get started :D
1. Setup Development Environment:
First, we need to install some tools to get started. So go ahead and download the below tools: (I am using Windows for this Tutorial. So the steps might be different for Linux or Mac.)
- Install NVM ( Node Version Manager)
- Install MongoDB Compass (Database)
- Install Postman ( API Testing )
- Install VSCode ( Code Editor)
- Install Google Chrome (Browser)
2. Setting up our Node Express APP
Lets build our Express App, We will be using the express-generator to create a boilerplate project.
Open the terminal or command prompt and type :
Starting a new project with the Express generator is as simple as running a few commands:
npm install express-generator -g
This installs the Express generator as a global package, allowing you to run the
express command in your terminal:
This creates a new Express project called
myapp which is then placed inside of the
myapp directory. Lets move the new created project:
Now we need to install the dependencies in this app :
npm is the default Node.js package manager. Running
npm install installs all dependencies for the project. By default, the
express-generator includes several packages that are commonly used with an Express server.
You can use other package managers like Yarn. Its faster than npm!
Once all the dependencies are installed, we can then start our express app locally :
SET DEBUG=myapp.* & npm start
This will start the app locally, you can visit http://localhost:3000 in the browser:
Now, our express app is ready, let’s open the app using VS Code , Open a new terminal and type :
cd myapp code .
This will open up the code editor with myapp project :
Currently the app uses ES5 syntax. In the next part, we will see on adding support to ES6 support to our APP.
You can view the Part -2 here
So Stay Tuned :D