node-api-project-template
This is a node api project template to see how I work
Node architecture
srcs
Sources folderdist
Folder for generated filestslint.json
TSLinter configuration filenodemon.json
Nodemon config file to watch projecttsconfig.json
Typescript config file
Code architecture
I always use the base like this:
- Logger defined in srcs/logger.ts
- Swagger defined in srcs/swagger.ts
- Stateless configuration setup with env srcs/config.ts
- Routes folder with a gloabal router
index.ts
srcs/routes - Controllers folder for express route handlers srcs/controllers
Code standard
As a linter I like to use standardjs here I use tslint with standard config
In package.json
I often have at least five scripts:
- start
- build
- watch
- lint
- test
I prefer to use each CLI on code with npm like that we doesn't need to install global package and CLI in node_modules will be used
Docker
I create a Dockerfile with mutlistage who first build project then run the outputed files in a second stage.