This is an example of how to setup Sequelize and Express together in a project for NodeJS 10 and above.
Feel free to download this and use as a starting point for your new project!
This example uses SQLite as a database engine, since it works directly with the filesystem and does not require extra configuration. Feel free to use another database engine - you just have to change the connection URL in the Sequelize constructor. Learn more in the Sequelize docs.
- Install dependencies with
npm installoryarn install - Run the express server with
npm start - Open your browser in
localhost:8080and try the example REST endpoints:localhost:8080/api/users(GET)localhost:8080/api/users/1(GET)localhost:8080/api/users(POST)- Body format:
{ username: 'john' }
- Body format:
localhost:8080/api/users/1(PUT)- Body format:
{ username: 'john' }
- Body format:
localhost:8080/api/users/1(DELETE)
Try to create a new model item.model.js and a new express route controller items.js to handle:
GETandCREATEin/api/itemsGET,PUTandDELETEin/api/items/:id
This example focuses only on how you will integrate Sequelize with Express in your backend. The choice of a front-end technology stack is left to you!
MIT