DEV Community

Cover image for Express starter with ORM, JWT, lint, logger, docker, etc
Rohit Ambre
Rohit Ambre

Posted on • Edited on

Express starter with ORM, JWT, lint, logger, docker, etc

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 for request body validation in POST APIs, uses 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 logo rohit-ambre / node-auth-mysql

    Node(Express), Mysql based app with Authentication Boilerplate.

  2. Non-relation with MongoDB

    GitHub logo rohit-ambre / node-auth-mongo

    Node(Express), MongoDB based app with Authentication Boilerplate.

please show some ❤️ by starring ⭐ 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.
  • Fastify app with MongoDB repo link.

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.

Photo by Markus Spiske on Unsplash

Top comments (0)