简体   繁体   中英

Console.log giving error in Node.js

I am newbie to Node. I have installed Node on my nginx server. Created a folder namely test in the root. Inside the test folder I have created a js file namely test.js.

I have written a simple Console.log("Hi") .

Now in the terminal I am running the following code:

node test.js

I am getting following error.

/root/test/test.js:1
(function (exports, require, module, __filename, __dirname) { console.log("HI...")ø
                                                                                  ^
SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:390:7)
    at startup (bootstrap_node.js:150:9)

Any idea what I am missing?

有一个错字 øconsole.log()

Console.log("Hi")

to reference the global console object in Node you need to use lowercase.

Your program would therefore be console.log("Hi")

Also, the error suggests you have an extra character after the console statement. Make sure the ø character is removed.

(函数(导出,需求,模块,__ filename,__ dirname){console.log(“ HI ...”)ø),有一个错字。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM