完美

[学习|工作|博客|交流平台|完美起航]
 详情

node v6.9.2下使用async/await的方法

时间:[2017-07-05 16:22:30] 作者:[ SmartZ ] 点击:[ 5771 ]

使用babel,配置.babelrc

{
    "presets": [
        ["env", {
            "targets": {
                "node": true
            }
        }]
    ]
}

相关依赖package.json

{
    "name": "xxxx",
    "version": "1.0.0",
    "description": "xxxx",
    "main": "./public/index.js",
    "scripts": {
        "test": "node ./public/index.js"
    },
    "keywords": [
        "xxxx"
    ],
    "author": "xxx",
    "license": "ISC",
    "devDependencies": {
        "babel-cli": "^6.24.1",
        "babel-plugin-transform-async-to-generator": "^6.24.1",
        "babel-plugin-transform-runtime": "^6.15.0",
        "babel-polyfill": "^6.23.0",
        "eslint": "^4.0.0",
        "eslint-config-google": "^0.8.0",
        "eslint-plugin-react": "^7.1.0"
    },
    "dependencies": {
        "babel": "^6.23.0",
        "babel-core": "^6.18.2",
        "babel-preset-env": "^1.6.0",
        "babel-preset-es2015": "^6.18.0",
        "babel-preset-stage-3": "^6.17.0",
        "babel-register": "^6.24.1",
        "babel-runtime": "^6.18.0",
        "bluebird": "^3.4.6",
    }
}

配置index.js

require('babel-register');
require('./app.js');

app.js为项目主运行文件

node ./public/index.js

 4   0
 相关评论