Git Product home page Git Product logo

node-express-boilerplate's Introduction

Express.js with Babel Boilerplate

Use the lates Javascript features with Node, Today

A mostly unopinionated starter project for using Babel and ES2017+ features in a Node.js server environment as well as providing linting and testing solutions. It provides the setup for compiling, linting and testing your code but doesn't make any further assumptions on how your project should be structured.

This boilerplate is based on vmasto's express-babel

It's a small improvement over Babel's official approach and express-generator.

Make sure you read the FAQ for more details and info.

Features:

Getting started

# Clone the project
git clone https://github.com/TheHashHub/node-express-boilerplate
cd node-express-boilerplate

# Make it your own
rm -rf .git && git init && npm init

# Install dependencies
npm install
npm run dev

This will launch a nodemon process for automatic server restarts when your code changes.

Linting

Linting is set up using ESLint. It uses ESLint's default eslint:recommended rules. Feel free to use your own rules and/or extend another popular linting config (e.g. airbnb's or standard).

Begin linting in watch mode with:

npm run lint

Environmental variables in development

The project uses dotenv for setting environmental variables during development. Simply copy .env.example, rename it to .env and add your env vars as you see fit.

It is strongly recommended never to check in your .env file to version control. It should only include environment-specific values such as database passwords or API keys used in development. Your production env variables should be different and be set differently depending on your hosting solution. dotenv is only for development.

Deployment

Deployment is specific to hosting platform/provider but generally:

npm run build

will compile your server into /dist, and

npm start

will run build (via the prestart hook) and start the compiled application from the /dist folder.

The last command is generally what most hosting providers use to start your application when deployed, so it should take care of everything.

You can find small guides for Heroku, App Engine and AWS in the deployment document.

FAQ

Where are all the configurations for ESLint, Jest and Babel?

In package.json. Feel free to extract them in separate respective config files if you like.

Should I use this?

Full disclosure: If you have to ask perhaps you should reconsider. There is some debate on whether to use Babel-transpiled code on the server or not. Personally, we think it's fine and we've found this setup to be a sensible approach in doing so. That said, we'd suggest to take anything you read online with a grain of salt and refrain from blindly using boilerplates without first investigating for yourself.

Node is very rapidly converging with the latest ECMAScript specification, and there's mostly full native support for ES2015 and ES2016. The need to transpile on the server is way smaller nowadays, albeit the language is constantly improving and transpiling will probably always be a part of our workflow. At the time of this writing the main benefits are mainly ES6 module syntax and async/await without flags.

In any case, you can simply remove transpilation and keep everything else that this kit has to offer.

If you see anything that needs improvement feel free to open an issue for discussion!

Twitter @thehashhub.

License

MIT License. See the LICENSE file.

node-express-boilerplate's People

Watchers

 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.