node.js 如何使用 sublime text 运行节点应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12124544/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run node app with sublime text
提问by angry kiwi
How would you run node app with sublime text? Like this, open the file app.js in sublime, go to menu->tools->build, and it just runs. Simple like that
您将如何使用 sublime text 运行节点应用程序?像这样,在sublime中打开app.js文件,进入menu->tools->build,它就运行了。就这么简单
采纳答案by angry kiwi
To run nodejs on sublime text, install node package "node dev" then create a sublime text build, the code should look like this
要在 sublime text 上运行 nodejs,请安装节点包“node dev”,然后创建一个 sublime text build,代码应如下所示
{
"cmd": ["node-dev", "$file"],
"selector" : "source.js",
"path" : "/usr/local/bin"
}
Now to run a nodejs app, go to menu->tools->build.
现在要运行 nodejs 应用程序,请转到菜单->工具->构建。
回答by govo
Cmd+Shift+P , search for "Nodejs::Default File Settings" ,it will open file "Node.js.sublime-settings". you'll see:
Cmd+Shift+P ,搜索“Nodejs::Default File Settings”,它将打开文件“Node.js.sublime-settings”。你会看到的:
{
// save before running commands
"save_first": true,
// if present, use this command instead of plain "node"
// e.g. "/usr/bin/node" or "C:\bin\node.exe"
"node_command": false,
// Same for NPM command
"npm_command": false,
"expert_mode": false,
"ouput_to_new_tab": false
}
modify
调整
"node_command": false,
“节点命令”:假,
to
到
"node_command": "/usr/local/bin/node",
"node_command": "/usr/local/bin/node",
if the node path is not the same with above, find it and change to yours.
如果节点路径与上面的不一样,找到它并更改为你的。
回答by James Harris
If you want to fix the plugin's path yourself. One option is changing Nodejs.sublime-build. It's located in the packages directory of sublime:
如果你想自己修复插件的路径。一种选择是更改 Nodejs.sublime-build。它位于 sublime 的包目录中:
Mac: ~/Library/Application Support/Sublime Text 2/Packages/Nodejs/Nodejs.sublime-build
Linux: ~/.config/sublime-text-2/Packages/Nodejs/Nodejs.sublime-build
Note: On latest OS X versions the Library folder is hidden. If that's the case, from the menu select Go > Go to Folder... and type ~/Library.
注意:在最新的 OS X 版本中,Library 文件夹是隐藏的。如果是这种情况,请从菜单中选择 Go > Go to Folder... 并键入 ~/Library。
Change "cmd": ["node", "$file"] to "cmd": ["/usr/local/bin/node", "$file"]
{
"cmd": ["/usr/local/bin/node", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.js",
"shell":true,
"encoding": "cp1252",
"windows":
{
"cmd": ["taskkill /F /IM node.exe & node", "$file"]
},
"linux":
{
"cmd": ["killall node; node", "$file"]
}
}
Lastly, open your *.js file and press command + b. Everything should just work fine now.
最后,打开您的 *.js 文件并按 command + b。现在一切都应该正常工作。
Linux Users: This file is identical across all operating systems. Finding the path to Nodejs.sublime-build may require running a search. In most cases it's located in ~/.config/sublime-text-2/Packages/Nodejs/Nodejs.sublime-build
Linux 用户:此文件在所有操作系统中都是相同的。找到 Nodejs.sublime-build 的路径可能需要运行搜索。在大多数情况下,它位于 ~/.config/sublime-text-2/Packages/Nodejs/Nodejs.sublime-build
回答by 3on
What is going on is that you don't have the right PATH setup for your terminal.
发生的事情是您的终端没有正确的 PATH 设置。
try this command in a regular terminal:
在常规终端中尝试此命令:
> which node
I peronaly get this:
我个人得到这个:
/usr/local/bin/node
As you can see this path is not in you environement path to add it in a regular terminal you would edit .bashrc or .bash_profile and add this line
如您所见,此路径不在您的环境路径中,要将其添加到常规终端中,您将编辑 .bashrc 或 .bash_profile 并添加此行
export PATH=/usr/local/bin:$PATH
Here well you just have to look at the docand find out that you need to modify the configuration file.
在这里,您只需查看文档并发现您需要修改配置文件。
If you have a JavaScript file open, by selecting selecting Tools -> Build Systems -> Nodejs and then hitting Ctrl + B, you will activate the node build system on your file and node will try to run it. You may need to add a path variable to the settings object for this if your node executable is not found
如果您打开了一个 JavaScript 文件,通过选择工具 -> 构建系统 -> Nodejs,然后按 Ctrl + B,您将激活文件上的节点构建系统,节点将尝试运行它。如果找不到您的节点可执行文件,您可能需要为此设置对象添加路径变量
Look at this.
看看这个。
回答by Nick Tulett
On xubuntu, I made the build command in Nodejs.sublime-build explicity use the terminal:
在 xubuntu 上,我使 Nodejs.sublime-build 中的 build 命令明确使用终端:
"cmd": ["xfce4-terminal", "--command", "node $file"]
"cmd": ["xfce4-terminal", "--command", "node $file"]

