如何在Windows的Node.js中运行hello.js文件?

windows Node.js

猴子达蒙A

2020-03-18

我正在尝试在一个名为hello.js的单独文件中运行用javascript编写的hello world程序

当前正在运行Windows版本的node.js。

该代码可以在控制台窗口中完美运行,但是如何在Windows环境中引用该路径

C:\abc\zyx\hello.js

在Unix中,我猜它显示的是$ node hello.js

我绝对不是Node.js的新手,如果我做错了什么,请纠正我。

我试过了

> node C:\abc\zyx\hello.js ----没工作

> C:\abc\zyx\hello.js -没用

UPDATE1:

将node.exe添加到了hello.js文件所在的文件夹中。
添加了指向文件夹c:\ abc \ zyx \的路径,但出现错误提示

ReferenceError:您好未定义

查看hello.js的内容

setTimeout(function() {
console.log('World!');
}, 2000);
console.log('Hello');

更新2:

到目前为止,我已经尝试了所有这些版本,但似乎都没有用可能是我做错了什么。

>node hello.js
>$ node hello.js
>node.exe hello.js
>node /hello.js
>node \hello.js
> \node \hello.js
> /node /hello.js
> C:\abc\xyz\node.exe C:\abc\xyz\hello.js
> C:\abc\xyz\node.exe C:/abc/xyz/hello.js
> hello.js
> /hello.js
> \hello.js
>node hello

参考我的文件结构

在此处输入图片说明

RESOLVED: Instead of running node.exe, try running in command prompt with the following option and it worked.

c:\>node c:\abc\hello.js
Hello
World! (after 2 secs)

第2142篇《如何在Windows的Node.js中运行hello.js文件?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

0个回答

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android