stasgm / nodeplate

Node.js boilerplate using Express.js, MongoDB and Typescript for your REST API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nodeplate logo

Introduction

Welcome to the Nodeplate repository.
Nodeplate is a Node.js boilerplate to start easily your new REST API using Express.js, MongoDB and Typescript.

Components

API Use-case

To illustrate the boilerplate usage, we're taking the case of an API giving "Product" informations stored in our MongoDB database. Each product has a "product_code".

Getting started

The commands are available in package.json.

Requirements

Before going directly to the installation, please make sure you have the following plateform/tools on your computer :

  • Latest NodeJS version
  • Yarn installed
  • MongoDB database (make sure you have a stored login)
Environnement setup

First of all, you have to create your environnement typescript files in the "../src/config/environnements" folder, based on the "template.ts" file :

  • dev.ts (developpement configuration)
  • prod.ts (production configuration)

Specify your API_URL, MongoDB connection, log path,... (see comments in template.ts)

Installation
$ yarn install
Starting server

In a developpement context run :

$ cross-env NODE_ENV=development nodemon --watch "src/**/*.ts" --exec ts-node src/app.ts

In a production context run :

$ cross-env NODE_ENV=production ts-node src/app.ts
Run specs
$ yarn jest
Eslint

To run Eslint on the src files :

$ eslint "src/**/*.ts"
Prettier

This project use prettier as a code formatter.

To check which src files are not formatted with prettier run :

$ prettier --check "src/**/*.ts"

To run prettier on all src files :

$ prettier --write "src/**/*.ts"
Intellij Plugins

For Intellij users (Webstorm or Ultimate), I advise you to install the following plugins for a better use :

About

Node.js boilerplate using Express.js, MongoDB and Typescript for your REST API

License:MIT License


Languages

Language:TypeScript 64.5%Language:JavaScript 29.0%Language:Dockerfile 3.6%Language:Shell 2.9%