Getting started with express.js

Angelo Poole
2 min readAug 16, 2020

--

how to set up a dev environment for express.js

Photo by Ethan McArthur on Unsplash

To begin, make a backend folder that will host your repository then create a git repo from here.

  1. npm init -y
  2. npm install express cors mongoose dotenv

from here we’ll have a lot of the tech that will be necessary to begin the development of a restful express backend API.

Here's a brief explanation of what each package does:

  1. express: a lightweight backend framework for node.js
  2. cors: cors stands for cross-origin resource sharing and this allows for Ajax requests to skip the same-origin policy and access resources from remote hosts. the cors package provides an express middleware that can allow cors with different options, this allows us to easily access something outside of our server from our server
  3. mongoose: make interacting with MongoDB trough node.js simpler
  4. dotENV: loads env variables through process.env

At this point you have access to what you need in order to get started working with the express, you just need the basic server.js file and require mongoose and express shown below

you’re then going to want to create a .env file and make a variable that is called ATLAS_URI and is assigned the URI given to you by MongoDB
make sure to change the password field to the password you chose when initializing your MongoDB server.

ATLAS_URI-URIHERE<password>

from here to test your server you can install another dependency called nodemon with:”>npm install nodemon” then running the command with

“nodemon server.js”

within your terminal.

--

--

Angelo Poole
Angelo Poole

Written by Angelo Poole

Software engineer, Graduate of Flatiron school. Currently volunteering! Looking to talk to fellow engineers, please send me a message!

No responses yet