Express starter with ORM, JWT, lint, logger, docker, etc
Tags: node, express, hacktoberfest
Published: 2020-10-13 15:18:31

When you are starting a new backend project in `Node.Js` using `express` there are things which are very common in every project and few files which are also required to be created in every project so, If you are going to start a new express project and want to quickly get started with basic app structure, database integration with ORM, JWT auth, linting, code styling, file-level logging, request validation, docker enabled then take a look here.

Every express project will have `server.js` or `index.js` file to create an express app and start listening on any port. In Database, tables will at least have `users` tables to store basic user details, and with users will surely have some sort of authentication mechanism, where mostly it's `JWT` based authentication, so by keeping these things in mind, I made 2 boilerplates express apps one for Relation database (MySQL) using `sequelize` ORM and second for Non-relational (MongoDB) database using `mongoose` ORM. Both of these apps have `User` model with basic user properties such as `email`, `firstName`, `lastName`, `password`. Password is stored in hashed format and for authentication, it returns JWT token on successful login which is used to fetch all users API. So basically these boilerplates/starters have 3 APIs.

1. POST: `/api/auth/signup`
2. POST: `/api/auth/login`
3. GET: `/api/user/users`

To imply best practices, these apps use `eslint` or `standard.js`, for code styling it uses `prettier`. (mysql one uses `standard.js` for linting and styling while mongo one uses `eslint` and `prettier` for code styling.)
Apps use [express-validator](https://www.npmjs.com/package/express-validator) for request body validation in `POST` APIs, uses [winston](https://www.npmjs.com/package/winston) logger for logging error or debug data in file and console. I have tried to keep folder and code structure very simple to understand and to make changes according to your need.

These are my two boilerplate repos
1. Relational with Mysql
{% github rohit-ambre/node-auth-mysql no-readme %}
2. Non-relation with MongoDB
{% github rohit-ambre/node-auth-mongo no-readme %}

please show some :heart: by starring :star: and making contributions in any form if you find anything.

And for developers who wants to contribute during this `hacktoberfest`, I would love to have contributions for the following stuff:
- Ideas for any new boilerplate repo.
- test setup (priority)
- unit test cases with optimum code coverage. (priority)
- better API documentation in markdown or etc
- bugs or issues

I'm also working on two more, boilerplates repos which are not yet complete to get started which are 
- Express in typescript using `TypeORM` with `Postgres` DB [repo link](https://github.com/rohit-ambre/express-ts).
- Fastify app with `MongoDB` [repo link](https://github.com/rohit-ambre/fastify-auth).

NOTE: *If you're going to contribute then before starting to work on it please create an issue explaining the bug or enhancement you want to work on, I'll assign it to you so, that no two users can work on the same thing*

Thank you, tell me what you think about it.


<span>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Markus Spiske</a> on <a href="https://unsplash.com/s/photos/starter?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>