Giter Club home page Giter Club logo

boilerplate-docker-node-express-jest's Introduction

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

boilerplate-docker-node-express-jest's People

Contributors

laisfrigerio avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.