Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node - Express - Typescript Project

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.

Getting Started

Pre-reqs

To build and run this app locally you will need a few things:

Install

  • npm install
  • npm start

Running

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

Features:

  • Nodemon - server auto-restarts when code changes
  • Express 4.0
  • Socket.io Websockets
  • Swagger 2.0
  • Cron jobs prepared

Included middleware:

  • routing-controllers
  • body-parser
  • express-validator
  • Winston Logger
  • JWT auth express-jwt
  • CORS

Developing

Commands

We use npm scripts as our build tool. Refer to the package.json script's entry for list of scripts.

TypeScript

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.

Environment

Database configuration, port setups, etc for NodeJS are maintained yaml config files in ~/config via node-config.

Debugging / Profiling

Node Inspector

NodeInspector is a visual debugging interface for NodeJS applications based on Chrome DevTools. It offers rich debugging and profiling.

VSCode

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

Webstorm is a rich JavaScript IDE by Jetbrains. It offers advanced code completion, debugging and profiling.

Resources

Similar Projects

References

Interesting

About

node-typescript-express-rest

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages