koa2 uses ES7 syntax, such as async and await, so it needs to be run after node7.6; but before node7.6, you can also use koa2, which is the babel, to run.
First, install babel and several modules of babel in the project:
npm install babel babel-register babel-preset-env --save
Then introduce the 'babel-register' module in the entry file
require('babel-register');
Then introduce the business code:
require('./');
In the configuration .babelrc file:
{ "presets": [ ["env", { "targets": { "node": true } }] ] }
Example:
:
require('babel-register'); require('./servers/devserver');
:
var koa = require('koa'); var app = new koa(); const request = require('request'); let port = || 8080; ("set port:" + + "; ip:" + ); (async (ctx) => { (); if (('/aaa') > -1) { ('content-type', 'text/javascript'); = ('http://127.0.0.1/', function(err, response, body) { (body); }); } }); (port);
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.