I just started to contact koa and it keeps prompting ctx=> This> error cannot be run. I can’t figure it out and can’t find the information. Please help me.
This is an error.
app.use(ctx => {
^
SyntaxError: Unexpected token >
at exports.runInThisContext (vm.js:69:16)
at Module._compile (module.js:432:25)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:349:32)
at Function.Module._load (module.js:305:12)
at Function.Module.runMain (module.js:490:10)
at startup (node.js:124:16)
at node.js:803:3
This is the source code
const Koa = require('koa');
const app = new Koa();
app.use(ctx => {
ctx.body = 'Hello Koa';
});
app.listen(3000);
console.log('app started at port 3000....');
習慣沉默2017-05-16 13:35:32
Rememberkoajs2
should be
app.use(async (ctx, next) => { await next(); });
Also check if the nodejs version is too low
天蓬老师2017-05-16 13:35:32
I found the reason. Sure enough, the node.js version is too low. Thank you, first floor