nodejs第一个hello world代码

听说nodejs很不错,下来学学!

一、到nodejs网站下载适合安装包, 地址:https://nodejs.org/en/download/

二、安装,狂点下一步

三、手写第一个Hello World,学任何一门语言的基础!

新建一个hello.js

function hello() {
console.log('Hello World!');
}
hello();

四、将hello.js放到nodejs安装目录,C:\Program Files\nodejs目录下

五、运行

打开cmd命令行窗口,输入cdC:\Program Files\nodejs

再输入node hello.js


六、应避免一个错误:

我开始直接打开node.js运行

node hello.js

SyntaxError: Unexpected identifier
   at Object.exports.createScript (vm.js:44:10)
   at REPLServer.defaultEval (repl.js:117:23)
   at bound (domain.js:254:14)
   at REPLServer.runBound [as eval] (domain.js:267:12)
   at REPLServer.<anonymous> (repl.js:279:12)
   at REPLServer.emit (events.js:107:17)
   at REPLServer.Interface._onLine (readline.js:214:10)
   at REPLServer.Interface._line (readline.js:553:8)
   at REPLServer.Interface._ttyWrite (readline.js:830:14)
   at ReadStream.onkeypress (readline.js:109:10)

 

猜你喜欢

转载自zhangshufei8001.iteye.com/blog/2377278