Template for backends with NodeJS + Express, ready to use in production!
APACHE-2.0 License
<a href="https://">Read the article</a>
<a href="https://github.com/Israel-Laguan/<express-production-template/issues">Report a Bug</a>
<a href="https://github.com/Israel-Laguan/express-production-template/issues">Request Feature</a>
![heroku][]
To get the Node server running locally:
npm install
to install all required dependenciesmongod
npm run dev
to start the local servermongoose-unique-validator
plugin helps us by formatting the error like a normal mongoose ValidationError
.app.js
- The entry point to our application. This file defines our express server and connects it to MongoDB using mongoose. It also requires the routes and models we'll be using in the application.config/
- This folder contains configuration for passport as well as a central location for configuration/environment variables.routes/
- This folder contains the route definitions for our API.models/
- This folder contains the schema definitions for our Mongoose models.In routes/api/index.js
, we define a error-handling middleware for handling Mongoose's ValidationError
. This middleware will respond with a 422 status code and format the response to have error messages the clients can understand
Requests are authenticated using the Authorization
header with a valid JWT. We define two express middlewares in routes/auth.js
that can be used to authenticate requests. The required
middleware configures the express-jwt
middleware using our application's secret and will return a 401 status code if the request cannot be authenticated. The payload of the JWT can then be accessed from req.payload
in the endpoint. The optional
middleware configures the express-jwt
in the same way as required
, but will not return a 401 status code if the request cannot be authenticated.
Contributions, issues and feature requests are welcome! Feel free to check the issues page.
Give a if you like this project!
Icons from:
Icons8
This project is licensed under the MIT Feel free to fork this project and improve it