Example of a RESTful API with JWT authentication using MariaDB as database and Sequelize as ORM.
This example app has been coded with Node.js v16.13.0. If you are using NVM just run:
nvm useThat will select the correct version of Node.js for you. Note: You may need to install it before using it.
Run:
npm installThis example app uses environment variables, copy the .env.example file to a new file called .env:
cp .env.example .envMake sure to fill and update the file with your own settings.
By default, sequelize-cli can not create a database for MariaDB via command line, you will need to create your own database manually. Make sure the database name matches the MARIADB_DATABASE env var in the .env file.
After creating the database, run the following command to create the tables automatically:
npx sequelize-cli db:migrateIt's a good idea to have some initial data in the database, to insert a few users into the db, run:
npx sequelize-cli db:seed:allThat will insert two users:
| First Name | Last Name | Password | User Type | |
|---|---|---|---|---|
| Isaac | Ramirez | [email protected] | pass_good | admin |
| Ragnar | Lothbrok | [email protected] | pass_good | user |
To get the application up & running in development mode, run:
npm run devThe server will start listening on port 8080 or the one configured in the PORT env var. Navigate to: