Microsoft JScript运行时错误:代码:800A1391'console'在运行node.js程序时未定义 [英] Microsoft JScript runtime error : Code : 800A1391 'console' is undefined while running node.js program

查看:3564
本文介绍了Microsoft JScript运行时错误:代码:800A1391'console'在运行node.js程序时未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是node.js的新手。在Windows机器上安装node.js后,我创建了一个名为myFirst.js的文件。该文件如下所示:

I am new to node.js. I have created a file named myFirst.js after installing node.js in Windows machine. The file looks like following :

console.log("Sweet .. Welcome to Node.js"); 

但是当我尝试导航到该目录并执行该文件时,它会抛出如下错误:

But when I try to navigate to that directory and execute the file it throws an error like the following :

甚至像

这样的命令

无效。我错过了什么?我如何执行我的第一个node.js代码块?

is not working. What am I missing ? How would I execute my first node.js code block ?

推荐答案

您必须在执行* .js文件前加上节点可执行文件,用于添加上下文,就像说使用节点脚本引擎打开此文件,而不是默认的Microsoft脚本引擎,它不能识别'控制台'对象。

You must prefix your execution of the *.Js file with the node executable to add context, as if to say, "open this file with the node scripting engine, rather than the default Microsoft scripting engine, which does not recognize the 'console' object."

因此,而不是简单地提供.Js文件的名称,如下所示:

Therefore, instead of simply providing the name of the .Js file, like so:

myFirst.js

将其更改为:

node myFirst.js

* .js文件的名称充当节点可执行文件的参数,然后执行,为您提供Sweet .. Welcome to Node.js语句。

The name of the *.js file acts as a parameter to the node executable, which is then executed, providing you with your "Sweet.. Welcome to Node.js" statement.

这篇关于Microsoft JScript运行时错误:代码:800A1391'console'在运行node.js程序时未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆