Skip to content

A docker boilerplate with node 18 + express + jest + supertest ๐Ÿณ

License

Notifications You must be signed in to change notification settings

laisfrigerio/boilerplate-docker-node-express-jest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

docker + node 18 + express + jest and supertest

A docker boilerplate with node 18 + express + jest + supertest ๐Ÿ’œ

๐Ÿ› ๏ธ Stack

  • nodejs: 18 + express
  • jest
  • supertest
  • docker

Docker version

We develop this boilerplate with the following docker version: 20.10.22

๐Ÿ“ Features

  • โ˜‘๏ธ nodejs 18 + express api
  • โ˜‘๏ธ test setup with jest + supertest
  • โ˜‘๏ธ running integration tests with docker
  • โ˜‘๏ธ running this application with docker

๐Ÿ’Ž Run application

    npm run docker:build
    npm run docker:run
  • Open a browser and type the following URL: http://localhost:49127

๐Ÿ’Ž Run tests

    npm run docker:build
    npm run docker:test

๐Ÿ’Ž How add eslint

  1. Install eslint:
    npm install eslint -D
    yarn add eslint -D
  1. Let's generate the .eslintrc.json:
    npx eslint --init
    yarn eslint --init

This command promotes you to multiple options, choose the following options:

  1. To check syntax and find problems, and enforce code style
  2. JavaScript modules > commonjs
  3. Does your project use TypeScript No/Yes In my case, I am not using TypeScript > No
  4. Where does the code run? > Node
  5. What format of the config file? > JSON
  6. 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": {}
}
  1. 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"
        ]
    }
}
  1. 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.

๐Ÿ‘ฉ Author

@laisfrigerio

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

A docker boilerplate with node 18 + express + jest + supertest ๐Ÿณ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published