Server boilerplate: Docker, Node, TypeScript, Nodemon, Husky, lint-staged, Eslint, Prettier, Pug, dotenv, Jest, TestCafé
- 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
Using Docker with volumes for Nodemon reloads:
> docker-compose up
Local machine:
> npm install
> npm run dev
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()
.env vars are undefined in the app, despite being imported and loaded first thing in the app:
import * as dotenv from "dotenv";
dotenv.config();
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/configThen, you don't need to require and load dotenv in your application code. So delete:
import * as dotenv from "dotenv";
dotenv.config();
- 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
Windows Fast startup might cause problems when using WSL2: https://www.tenforums.com/tutorials/4189-turn-off-fast-startup-windows-10-a.html