An error occurs when running the code as demonstrated. You need to adjust the method.
Http://koajs.cn/
To install the following
$ npm install -g n
$ n 0.11.12
$ node --harmony my-koa-app.js
Note: If you run node hello. js directly in the command line, an error is returned. The error is generally as follows:
Function
* Respond (next ){
^
Syntaxerror: Unexpected token *
At module. _ compile
(Module. JS: 439: 25)
At object. Module. _ extensions.. js
(Module. JS: 474: 10)
At module. Load
(Module. JS: 356: 32)
At function. Module. _ load
(Module. JS: 312: 12)
At module. Require
(Module. JS: 364: 17)
At require
(Module. JS: 380: 17)
At object. (C: \ Program
Files \ nodejs \ node_modules \ Koa \ index. JS: 2: 1
8)
At
Module. _ compile (module. JS: 456: 26)
At
Object. Module. _ extensions.. js (module. JS: 474: 10)
At
Module. Load (module. JS: 356: 32)
This is because app. Use (Function
* () {The statement contains *. This method is called generator functions. Generally, the function * () {...} is written.
Which supports es6yieldConcept (what? You don't know what it isyield... % $ # @ %... Well, I don't know either. But I believe we will see it later. Please be patient .). So we need to let this new JavaScript method be compiled, we need to run the node
Add a harmony parameter to the Command (well, you know what a crab is. Oh, right. The English meaning of harmony is harmony, so that the compiler can accept not only the old JavaScript syntax but also the new era syntax .) The statement is as follows:
Node -- harmony hello. js