当前位置: 首页 > 软件库 > Web应用开发 > >

express-babel

授权协议 MIT License
开发语言 JavaScript
所属分类 Web应用开发
软件类型 开源软件
地区 不详
投 递 者 端木存
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Express.js with Babel Boilerplate

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.

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 git@github.com:vmasto/express-babel.git
cd express-babel

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

# Install dependencies
npm install

# or if you're using Yarn
yarn

Then you can begin development:

# yarn
yarn run dev

# npm
npm run dev

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

Testing

Testing is powered by Jest. This project also uses supertest for demonstrating a simple routing smoke test suite. Feel free to remove supertest entirely if you don't wish to use it.

Start the test runner in watch mode with:

# yarn
yarn test

# npm
npm test

You can also generate coverage with:

# yarn
yarn test --coverage

# npm
npm test -- --coverage

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:

# yarn
yarn run lint

# npm
npm run lint

To begin linting and start the server simultaneously, edit the package.json like this:

"dev": "nodemon src/index.js --exec \"node -r dotenv/config -r babel-register\" | 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:

# yarn
yarn run build

# npm
npm run build

will compile your src into /dist, and

# yarn
yarn start

# npm
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.

Tips / Debugging

FAQ

Where is all the configuration for ESLint, Jest and Babel?

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

Why are you using babel-register instead of babel-node?

babel-node contains a small "trap", it loads Babel's polyfill by default. This means that if you use something that needs to be polyfilled, it'll work just fine in development (because babel-node polyfills it automatically) but it'll break in production because it needs to be explicitely included in Babel's CLI which handles the final build.

In order to avoid such confusions, babel-register is a more sensible approach in keeping the development and production runtimes equal. By using babel-preset-env only code that's not supported by the running environment is transpiled and any polyfills required are automatically inserted.

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, I think it's fine and I've found this setup to be a sensible approach in doing so. That said, I'd suggest to take anything you read online with a grain of salt and refrain from blindly using boilerplates without first investigating personally.

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!

You can also find me on twitter at @vmasto.

License

MIT License. See the LICENSE file.

  • 在package.json中 "dependencies": { "babel": "^6.23.0", "babel-cli": "^6.24.1", "babel-core": "^6.24.0", "babel-preset-es2015": "^6.24.0", "babel-preset-stage-3": "^6.22.0", "babe

  • 1.首先在package.js中加入如下的依赖包,并需要修改启动的路径(后面有说要自己新增个index.js文件) { "name": "express-app", "version": "0.0.0", "private": true, "scripts": { // 需要改变的启动路径 "start": "node ./index.js", "devstar

  • 一、安装nodemon实现项目热更新; 以前node中不管用什么框架,每次修改代码之后,都需要重新npm start 才能看到改动的效果,非常麻烦,所以这里引入nodemon模块,实现了不用重启也能自动更新这样的好处 1.全局安装nodemon npm install -g nodemon 或者安装到本地 npm install nodemon --save 2.在项目目录下创建 nodemo

 相关资料
  • 快递概述 Express是一个最小且灵活的Node.js Web应用程序框架,它提供了一组强大的功能来开发Web和移动应用程序。 它有助于基于节点的Web应用程序的快速开发。 以下是Express框架的一些核心功能 - 允许设置中间件以响应HTTP请求。 定义路由表,该表用于基于HTTP方法和URL执行不同的操作。 允许基于将参数传递给模板来动态呈现HTML页面。 安装Express 首先,使用N

  • art-template for express. Install npm install --save art-template npm install --save express-art-template Example var express = require('express'); var app = express(); app.engine('art', require('exp

  • Serverless Express ⎯⎯⎯ This Serverless Framework Component enables you to take existing Express.js apps and deploy them onto cheap, auto-scaling, serverless infrastructure on AWS (specifically AWS HTT

  • 囊括了perl程序员必需的编写和调试的所有工具,无论是对新手还是对老手都很合适

  • Simple and fast HTTP-Framework with the touch of expressjs State of this project I created this years ago and I'm no longer actively working with java. If anyone is interested maintaining this (and ha

  • Next.js + Express Next.js project using Spotify API (See demo). Build Setup # Dependencies$ npm install# Serve at at localhost:3000$ npm run dev Docs Next.js Now React Express