In this lab, we'll be building our very own Express Sequelize API from nothing! We'll start in the design process with an ERD and proceed all the way through to testing our API out with Insomnia.
fork
andclone
- Read through the FULL INSTRUCTIONS before starting this lab
Your goal is to create a Node/Express/Sequelize server that can be queried externally. To test this, you'll need Insomnia.
- Create an ERD to establish what sort of models you'll want to be working with. (No more than
3
models should be created). - Create an entry point by
touching
eitherserver.js
,app.js
, orindex.js
npm init -y
to initialize your project with Nodenpm i pg sequelize express cors body-parser
to install proper dependenciesnpm i @ngneat/falso
to install dependencies- Set up your scripts the in
package.json
to run your server. sequelize init
to initialize this as a sequelize project- Make sure that the dialect in your config.json is
postgres
, remove unnecessary fields, and change the name of your database to the name you'd like to use - Create your database with
sequelize db:create
- Create your models with
sequelize model:generate --name --attributes
- Set up proper associations between your models
- Migrate your database with
sequelize db:migrate
- Create
routes
andcontrollers
folders with anAppRouter.js
in your Routes folder - Set up your server entry point like this:
const app = require('express')()
const cors = require('cors')
const AppRouter = require('./routes/AppRouter')
const PORT = process.env.PORT || 3001
app.use(cors())
app.use(express.json())
app.get('/', (req, res) => res.json({ message: 'Server Works' }))
app.use('/api', AppRouter)
app.listen(PORT, () => console.log(`Server Started On Port: ${PORT}`))
- Your API should have at least 3 models with associations between them
- At least one model should have queries for full CRUD functionality
If completed correctly, you've gone through the entire process of conceptualizing your database with an ERD, starting a Node project from scratch with npm init -y
, and adding in Sequelize, setting up models/routes/controllers, model associations, and queries to interact with the database. This is everything you need to set up your backend for a full stack application! Feel the power!