Koa note running error

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.