简体   繁体   English

Console.log在Node.js中给出错误

[英]Console.log giving error in Node.js

I am newbie to Node. 我是Node的新手。 I have installed Node on my nginx server. 我已经在Nginx服务器上安装了Node。 Created a folder namely test in the root. 在根目录中创建了一个文件夹,即test。 Inside the test folder I have created a js file namely test.js. 在测试文件夹中,我创建了一个js文件,即test.js。

I have written a simple Console.log("Hi") . 我已经编写了一个简单的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. 要在Node中引用全局控制台对象,您需要使用小写字母。

Your program would therefore be console.log("Hi") 因此,您的程序将为console.log("Hi")

Also, the error suggests you have an extra character after the console statement. 同样,该错误表明您在console语句后还有一个额外的字符。 Make sure the ø character is removed. 确保删除了ø字符。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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