Skip to content
This repository has been archived by the owner on Apr 15, 2021. It is now read-only.
/ tsexpress Public archive

Simple CRUD API in Node.js with TypeScript and Express

Notifications You must be signed in to change notification settings

lkurzyniec/tsexpress

Repository files navigation

tsexpress

Repository contains

  • NodeJS
  • Express
  • TypeScript
  • ts-node-dev
  • InversifyJS
  • MongoDB with mongoose
  • dotenv and envalid
  • cors and helmet
  • cookie-parser and json-ignore
  • Swagger and SwaggerUI
  • express-validator, class-transformer, class-validator
  • express-promise-router
  • bcrypt and jsonwebtoken
  • jest (unit tests)

What I like in this solution

  • DI container (by InversifyJS) and injection of dependencies
  • modularity - build at the top of SOLID rules, lowly coupled
  • unit tests (with jest)

Start

Start MongoDB in Docker

Create volume to persist data.

docker volume create --name=mongodata

Run container.

docker run --name mongodb -v mongodata:/data/db -d -p 27017:27017 mongo:latest

Configuration (environment variables)

Create .env file in the root directory as follows:

MONGO_USER=
MONGO_PASSWORD=
MONGO_HOST=localhost
MONGO_PORT=27017
MONGO_DATABASE=libraryDB
APPLICATION_PORT=5000
DEBUG=true
TOKEN_EXPIRATION_IN_MIN=15

Instal dependencies

Install dependencies executing npm install.

Start the application

Type npm run dev in terminal, the application will be available under http://localhost:{APPLICATION_PORT}/ where APPLICATION_PORT is environment variable. By default is http://localhost:5000/.

To interact with API you can either send requests with Postman or send exemplary request from http queries file with REST Client which is VSCode extension. If you choose the second option, then remember to double check your PORT value from .env configuration file with @apiUrl variable.

Swagger documentation is under http://localhost:5000/swagger/, but there is not much.

About

Simple CRUD API in Node.js with TypeScript and Express

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •