A docker boilerplate with node 18 + express + jest + supertest π
- nodejs: 18 + express
- jest
- supertest
- docker
We develop this boilerplate with the following docker version: 20.10.22
- βοΈ nodejs 18 + express api
- βοΈ test setup with
jest
+supertest
- βοΈ running integration tests with docker
- βοΈ running this application with docker
npm run docker:build
npm run docker:run
- Open a browser and type the following URL:
http://localhost:49127
npm run docker:build
npm run docker:test
- Install eslint:
npm install eslint -D
yarn add eslint -D
- Let's generate the
.eslintrc.json
:
npx eslint --init
yarn eslint --init
This command promotes you to multiple options, choose the following options:
- To check syntax and find problems, and enforce code style
- JavaScript modules >
commonjs
- Does your project use TypeScript No/Yes In my case, I am not using TypeScript >
No
- Where does the code run? >
Node
- What format of the config file? >
JSON
- Would you like to install them now with npm? > In my case, I am not using npm
No
After finishing these promote options, a eslintrc.json
file will be created with the following configuration:
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 12
},
"rules": {}
}
- ESlint rules:
We will add additional eslint rules to this file. So you can override the entire content of this file with the following:
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true,
"jest": true
},
"extends": "eslint:recommended",
"overrides": [
],
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {
"indent": [
"error",
2
],
"no-mixed-spaces-and-tabs": "warn",
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"no-unused-expressions": [
"error",
{
"allowTernary": true
}
],
"no-unused-vars": [
"error",
{
"argsIgnorePattern": "request|response|next|__"
}
],
"space-infix-ops": "error",
"space-unary-ops": "error",
"no-multiple-empty-lines": [
"error",
{
"max": 2,
"maxEOF": 1
}
],
"no-whitespace-before-property": "error",
"object-property-newline": [
"error",
{
"allowAllPropertiesOnSameLine": true
}
],
"space-before-function-paren": [
"error",
"always"
],
"arrow-spacing": [
"error",
{
"before": true,
"after": true
}
],
"space-before-blocks": [
"error",
"always"
]
}
}
- Run tests with
jest
I just added "jest": true
to env, because I want to apply unit testing using jest to our node project. Extra rules were added to the rules section as well.
This project is licensed under the MIT License - see the LICENSE.md file for details