Build a Rest API w Node & Express – JSM


Node

Updated Aug 20th, 2021

Published 7/12/20

1 hour project

Npm init, install express

Add type module to package.json file to be able to use import/export syntax

Import body parser fr body parser

app.use()

app.listen()

Install nodemon as dev dependency to prevent having to start/stop server. Add nodemon to script in package.json file

Need to create sample route using app.get()

Create 5 routes:

Get / users finds all users

Post / users creates a user

Get / users / : ID finds user details

Delete / users /: ID deletes a user

Patch / users /: ID updates at user

Create a routes / users.js file. All routes in here go to /users/

Import express and initialize router

Add a user.json file and a users.json file to represent mock database

May want to download Chrome extension JSON formatter.

Left the chat at 22m