- expressjs - The server for handling and routing HTTP requests
index.jsThe entry point to our application. This file defines our express server and connects it to all the middlewares needed. It also requires the routes and models we'll be using in the application.api/This folder contains the route definitions for our API.migrations/Here we have some migrations (in SQL for easy portability) to run before start the server.server/This folder contains configuration for the app as well as a central location for configuration/environment variables.service/This folder contains the actions and queries for each Table.
Notice that the code don't use console.log(), instead uses a custom logger built with winston and morgan. All the important events are saved to logs/ folder and shows in the terminal. So if you run into any error and want to check the available info, visit the logs/ folder!
If an error happens the server must restart as is using nodemon in dev and pm2 in production. Also note I used extensively try...catch to avoid Unhandled Errors.
In api/v1/index.js, we define a error-handling middleware for handling inputs: ValidationError. This middleware will respond with a 422 status code and format the response to have error messages the clients can understand
Its made in MySQL. I also don't use an ORM as we usually don't need it if we know some SQL query build (or can use Google).
I defined some migrations to bootstrap a new server, you can use it by running npm run set-db:dev and have the migrations and seed run.
For databases I recommend using Heroku Free Tier. If you want to check the changes in DBs, I recommend pgweb.
- GET
/ping
curl https://fast-shopping-backend.herokuapp.com/ping