简体   繁体   English

如何在node.js中启动脚本/应用程序?

[英]How to start a script/app in node.js?

If I type console.log('Hello World'); 如果我输入console.log('Hello World'); in node.js it works, I get the "Hello World" message back. 在node.js中它起作用了,我收到了“ Hello World”消息。

But if I make a "helloworld.js" document with console.log('Hello World'); 但是,如果我使用console.log('Hello World');创建一个“ helloworld.js”文档console.log('Hello World'); inside and then type "node helloworld.js" in node then nothing happens. 在内部,然后在节点中键入“ node helloworld.js”,则什么也不会发生。

I have tried placing the script in same folder as node.js but still doesn't work. 我尝试将脚本与node.js放在同一文件夹中,但仍然无法正常工作。

Make sure that you're not running Nodejs.exe because that is the REPL . 确保您没有运行Nodejs.exe因为那是REPL

Instead you should open a regular Command Prompt window ( cmd.exe ) and run the command 相反,您应该打开常规的命令提示符窗口( cmd.exe )并运行命令

node helloworld.js

Make sure you run this command in the directory where the js file exists, the node application path is mapped in your environment settings. 确保在js文件所在的目录中运行此命令,节点应用程序路径已映射到您的环境设置中。

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

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