Skip to content

AbbeBlubb/node-ts

Repository files navigation

Server boilerplate: Docker, Node, TypeScript, Nodemon, Husky, lint-staged, Eslint, Prettier, Pug, dotenv, Jest, TestCafé

Features

  • Dockerized environment
  • Node
  • TypeScript
  • Jest test runner with ts-jest as preset
  • Nodemon reloads on change with the TS engine
  • .env for secrets
  • Express server boilerplate
  • Pug templates returned from endpoints
  • ESLint with Prettier
  • Husky with lint-staged

Start dev-mode

Using Docker with volumes for Nodemon reloads:

> docker-compose up

Local machine:

> npm install
> npm run dev

Tests

Unit tests:

> npm test // Run and get coverage
> npm test:watch // Test watcher

E2E-tests:

> npx testcafe chrome // With full browser
> npx testcafe --live --disable-screenshots // No screenshots when live mode
> npx testcafe chrome --disable-screenshots // with .debug()

Preload dotenv file

Problem

.env vars are undefined in the app, despite being imported and loaded first thing in the app:

import * as dotenv from "dotenv";
dotenv.config();

Solution

If using import in the app instead of require, preload the dotenv file when starting the app:

> node -r dotenv/config app.js

When using Nodemon, do this in the Nodemon config. In nodemon.json -> execMap -> ts, add:

-r dotenv/config

Then, you don't need to require and load dotenv in your application code. So delete:

import * as dotenv from "dotenv";
dotenv.config();

If port "already in use"

Kill process

  • If problems with port "already in use", Linux:
> lsof -i :6000 -t | xargs kill
  • If changing the port number in .env, remember to change the port mapping in docker-compose.yml

Turn off Windows Fast startup

Windows Fast startup might cause problems when using WSL2: https://www.tenforums.com/tutorials/4189-turn-off-fast-startup-windows-10-a.html

About

Server boilerplate: configuration for Docker, Node, TypeScript, Nodemon, Husky, lint-staged, Eslint, Prettier, Pug, dotenv, Jest, TestCafé

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors