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 install
oryarn install
- Run the express server with
npm start
- Open your browser in
localhost:8080
and 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:
GET
andCREATE
in/api/items
GET
,PUT
andDELETE
in/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