Giter Club home page Giter Club logo

dmj-back-end's Introduction

Express Sequelize API from Scratch

Baloo

Overview

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.

Getting Started

  • fork and clone
  • Read through the FULL INSTRUCTIONS before starting this lab

Instructions

Your goal is to create a Node/Express/Sequelize server that can be queried externally. To test this, you'll need Insomnia.

Recommended Process

  • 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 either server.js, app.js, or index.js
  • npm init -y to initialize your project with Node
  • npm i pg sequelize express cors body-parser to install proper dependencies
  • npm 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 and controllers folders with an AppRouter.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}`))

Requirements

  • Your API should have at least 3 models with associations between them
  • At least one model should have queries for full CRUD functionality

Recap

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!

Dance

Resources

dmj-back-end's People

Contributors

tylusdawkins avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.