/express-mongoose-template

A template Node.js project with express, mongoose and TypeScript.

Primary LanguageTypeScript

express-mongoose-template

Quick Start

Get started developing...

You need to create a .env file and configure your database at first, then set up the database and start developing / testing.

# install deps
yarn install

# run in development mode
yarn dev

# run tests
yarn test

# check code styles
yarn lint

# check type errors
yarn typecheck

Install Dependencies

Install all package dependencies (one time operation)

yarn install

Run It

Run in development mode:

Runs the application is development mode. Should not be used in production

yarn dev

or debug it

yarn dev:debug

Run in production mode:

Compiles the application and starts it in production mode

yarn compile
yarn start

Test It

Run the Mocha unit tests

yarn test

or debug them

yarn test:debug

Run the tests and output a JUnit-style XML test results file at ./test/test-results.xml

yarn test:junit

Try It

Make sure the database is running

  • Open you're browser to http://localhost:3000
  • Invoke the /examples endpoint
    curl http://localhost:3000/api/v1/examples

Debug It

Debug the server:

yarn dev:debug

Debug Tests

yarn test:debug

Debug with VSCode

Use the configurations in .vscode/launch.json file

Lint It

Check types and fix all linter errors

Check code styles

yarn lint
yarn lint:fix  # fix linter errors as well

Check type error

yarn typecheck

About

This template project was originally generated by cdimascio/generator-express-no-stress-typescript, and added with mongoose and several DevOps tools (Dependabot and GitHub Actions).

What you get!

  • Typescript - Typescript is a typed superset of JavaScript that compiles to plain JavaScript
  • Express.js - Fast, unopinionated, minimalist web framework for Node.js
  • Mongoose - Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment.
  • Pino - Extremely fast node.js logger, inspired by Bunyan. It also includes a shell utility to pretty-print its log files
  • dotenv - Loads environment variables from .env for nodejs projects
  • Swagger - is a simple yet powerful representation of your RESTful API.
  • SwaggerUI - dynamically generate beautiful documentation and sandbox from a Swagger-compliant API
  • express-openapi-validator - An OpenApi validator for ExpressJS that automatically validates API requests using an OpenAPI 3.x specification

More information here