The main purpose of this repository is to show a good end-to-end project setup for writing Node code in TypeScript using Express and a NOSQL DB.
To build and run this app locally you will need a few things:
npm installnpm start
When running the project locally with start, the swagger docs will be deployed at: http://localhost:8080/docs, and the bearer token for authorization should be as follows:
HEADER (LOCALHOST BASED ON DEFAULT SECRET KEY 'your-secret-whatever')
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEiLCJuYW1lIjoiSmF2aWVyIEF2aWxlcyIsImVtYWlsIjoiYXZpbGVzbG9wZXouamF2aWVyQGdtYWlsLmNvbSJ9.rgOobROftUYSWphkdNfxoN2cgKiqNXd4Km4oz6Ex4ng
| method | resource | description |
|---|---|---|
GET |
/users |
returns the collection of users present in the DB |
GET |
/user/:id |
returns the specified id user |
POST |
/user |
creates a user in the DB (object user to be includued in request's body) |
PUT |
/user |
updates an already created user in the DB (object user to be includued in request's body) |
DELETE |
/user/:id |
deletes a user from the DB |
- Nodemon - server auto-restarts when code changes
- Express 4.0
- Socket.io Websockets
- Swagger 2.0
- Cron jobs prepared
- routing-controllers
- body-parser
- express-validator
- Winston Logger
- JWT auth express-jwt
- CORS
We use npm scripts as our build tool. Refer to the package.json script's entry for list of scripts.
If you are installing a new third-party project, you will likely need to install the typings for that
project like so npm install @types/body-parser --save-dev. If types are not available
for your module read here
When you npm install the project, tslint is also installed
at the global level. It is advised you setup TSLint in your editor before commiting code.
Database configuration, port setups, etc for NodeJS are maintained yaml config files in ~/config
via node-config.
NodeInspector is a visual debugging interface for NodeJS applications based on Chrome DevTools. It offers rich debugging and profiling.
VSCode is a free code editor by Microsoft. It offers rich debugging capability and integration with NodeJS and TypeScript. I've pre-configured VSCode to automatically run build tasks/etc when you click debug.
Webstorm is a rich JavaScript IDE by Jetbrains. It offers advanced code completion, debugging and profiling.