Git Product home page Git Product logo

express-starter's Introduction

Express ES6 Starter

Build Status Maintainability Test Coverage Build Status

A custom NodeJS starter project with preconfigurations and templates to help you ship quality code early and often.

Table of Contents

Express Server

This project uses Express, a minimalist web framework for Node.js. It's lightweight and great for APIs.

Development

Using nodemon, the express server is automatically restarted when the src directory changes.

npm run server

The server defaults to port 3000. You can change it by setting the PORT environment variable.

Production

In production, run the server using just node:

npm start

Code Quality ๐Ÿ‘Œ

Jasmine is preconfigured and an example spec showing how to test Express apps is included. Just as important as testing but often forgotten is linitng. As author of Clean Code Robert Martin wrote:

Consistent indentation style was one of the most statistically significant indicators of low bug density.

Unit Specs with Jasmine

Unit tests leverage the Jasmine testing framework. They are executed with the standard NPM test command.

npm test

Unit specs:

  • must use .spec.js as a suffix
  • are preferably saved in the /specs, but they will be picked up anywhere
  • are executed randomly

For your convenience context() is also aliased to describe(), which helps nested syntax:

describe ('login()', () => {
  context ('valid credentials', () => {
    it ('returns true', () => {
      ...
    })
  })
  context ('invalid credentials', () => {
    it ('returns false', () => {
      ...
    })
  })
})

ES Linter

This project is also linted for code consistency with the recommended rule set, plus some custom changes, most notably:

Semicolons are not allowed:

// OK
let foo = bar

// will error
let foo = 'bar';

Spaces are required before the function parenthesis:

// OK
function (foo) {
  return true
}

// Fails
function(foo) {
  return true
}

Consistent spacing inside curly braces, for example:

// OK
import { app }

// Fails
import {app}

To see all adjustments, see the .eslintrc file.

Autofix Problems

You can autofix most common linting offenses with this command:

npm run lint:fix

Development Workflow

In development however, you can leverage auto reloading with:

npm run dev

which will simultaneously run and watch:

  • server
  • unit specs
  • linter

Or you can run them separately:

npm run server
npm run lint:watch
npm run test:watch

Preflight Command

Before I push code, I like to check if it will pass all continuous integration stages with a simple command that runs all the stages:

npm run preflight

If you wanted to, you could also configure a githook to ensure all your commits are green.

Docker Setup

For your convenience, there is an included Dockerfile and docker-compose.yml, which help jumpstart your microservice architecture.

These presets save you from common gotchas:

  • Dockerfile: package.json is copied first to avoid the heavy npm install step on successive builds.
  • docker-compose.yml: note that node_modules is mounted separately. This is required because native bindings can differ between the container and your development computer.
  • Included .dockerignore to avoid copying giant node_modules folder on build.

Note these files are configured for development only. If you plan to use them in production, you will make adjustments, e.g. use a different base image.

Jenkins Pipeline

There is a sample Jenkinsfile which a declarative pipeline including the following common stages:

  • checkout
  • install dependencies
  • run linter
  • run unit specs

Automated Semantic Versioning

This project uses standard-version for automatic semantic versioning and change logs.

  1. Commit messages must follow the Conventional Commits standard.

  2. When you are ready to release, just run:

npm run release

which will automatically:

  • update your CHANGELOG.md
  • tag your git repository

Depending on your commit messages, standard-version will automatically determine if it's a major, minor or patch release.

express-starter's People

Contributors

dependabot[bot] avatar julie-ng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.