Using Babel

If you're using an older version of Node (< 7.6), you will need to use a transpiler such as Babel to make async functions compatible with your version of Node. Koa recommends using Babel's require hook, as seen in the example in the following code snippet (https://babeljs.io/docs/en/babel-register/):

require('babel-register');

// require the rest of the app that needs to be transpiled after the hook

const app = require('./app');

You can then install the transforms you would need, depending on your version of Node. If you are using V6 of Node, you would not need most of the transforms, since it already supports a lot of ES6 features. At the minimum though, you would need the transform-async-to-generator plugin. You can define this in your .babelrc file, as follows:

{
"plugins": ["transform-async-to-generator"]
}

According to the Koa documentation, you can also use the env preset with a target option "node": "current" instead.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.70.101