A basic, pre-configured Node.js app to be used as starting template using for example degit. Includes the following pre-configured:
- Node 20
- Typescript 5 with path mapping from
@/*tosrc. So@/modules/foomaps to./src/modules/foo. The path mapping is fixed automatically when building, so the resulting Node.js JS project can resolve files. - Eslint configured for Typescript
- Prettier
- Jest testing using TS, via
ts-jest. - Uses
esbuildinstead ofts-nodefor developing. Blazing fast you know. - Dockerfile with multi-step build based on
slimimage (only 185Mb base image size after compilation). - Basic Github pipeline (
ci.yml) that cachesnode_modules, and then runs lint, test and compile TS onpushandpull_requesttomainbranch only.
A note on slim base image: see here Image Variants regarding this. In case something wrong happens during the build, switch to node-20 image for safety, specially if using dependencies with native binaries (like sharp for image manipulation and so on).
Node version 20, all dependencies latests versions as of May 20th 2024.
Create a new Node service based on this repo with
npx degit cdelaorden/node-ts-service
This is fast and doesn't include git info. Is just a fresh copy of the latest version.
- Modify the README and
package.jsondetails, so they don't point to this repository anymore (url,author,name,bugs,homepageand so on). - Add your preferred stack! Choose a DB, add a
docker-compose.yamlfor local development, add dependencies and code your app. This simply is the starting point, with some commands and configurations ready.
-
npm run devStarts dev environment locally with superfastesbuildtranspilation +nodemonfor hot reload. -
npm testSingle run of all tests with Jest -
npm run tddRuns test with Jest in watch mode -
npm run ts-compileCompiles TS withtsc(slower, but real type checking) -
npm run lintRuns Eslint -
npm run coverageRuns Jest and outputs coverage info
-
npm run buildCompiles TS tobuildoutput (which is .gitignored) -
npm run startFor production running, executes JS-compiled app inbuild/index.js(needs previousbuildstep) -
docker build .Builds the Docker image. Remember to tweak theDockerfileif custom dependencies are needed inside the container for your app.