Boilerplate
Note: Login is implemented, but the middleware to verify if user have session and router protection not finished yet
This repository contains my boilerplate to build an API Rest using NodeJS, TypeScript, ExpressJS and Mongoose (MongoDB).
I built this boilerplate after see some videos and try some times. When I finished all tries and solve some problems, I join all code in this repository to future projects.
This repository is public and I hope is useful to other people.
Folder Structure
In this repository you can find folders shown below:
.
└── src
├── configs
├── controllers
├── exceptions
├── middlewares
├── models
│ └── interfaces
└── routes
The folder src/configs
contains all code related with configs, like Mongoose connection.bg-0
Beyond that folders, you can find Babel (babel.config.json
) and TypeScript (tsconfig.json
) configuration file, as also ESLint (.eslintrc
and .eslintignore
), Nodemoon (nodemoon.json
) and Prettier (.prettierrc
) configuration files.
Notes
About TypeScript: in
tsconfig.json
you can see the configuration I use. I create custom paths to use in all.ts
files, this way you not need use relative paths, for example, toconfigs/
folder, I create@configs
path, and to use:import mongoose from '@configs/mongoose'
. For me, this is a good functionality in TypeScript and help you to create a clean imports.
Custom Paths - TypeScript
"paths": {
"@models/*": ["./models/*"],
"@controllers/*": ["./controllers/*"],
"@views/*": ["./views/*"],
"@configs/*": ["./configs/*"],
"@middlewares/*": ["./middlewares/*"],
"@exceptions/*": ["./exceptions/*"],
"@routes/*": ["./routes/*"],
"@index-routes": ["./routes"]
},