I justed started learning JavaScript. While doing that, I got tired of embedding my JavaScript code into an HTML document in order to run it in the browser. I thought it wou
Mac users, type which node
in terminal. It outputs the path of the node executable, which in most cases is /usr/local/bin/node
. Now create a new build system (Tools > Build System > New Build System
) with the following settings in Sublime Text.
{
"cmd": ["/usr/local/bin/node", "$file"],
"selector": "source.js"
}
May be it depends on environment variables -- try to use full path to node instead of just "nodejs". It worked for me on Mac OS (e.g. /usr/local/node instead of just node)
The method #2 of the link below solved for me:
http://www.wikihow.com/Create-a-Javascript-Console-in-Sublime-Text
Tested on Ubuntu Linux. Use a file selector as below:
{
"cmd": ["node", "$file"],
"selector": "*.js"
}
Normally
"cmd":["node",$file]
would work. However there is no way to stop the server than. I've found out the best solution which opens server in new console and the closes it automatically. I also works fine with supervisors or node-inspector
"cmd" : ["start", "cmd.exe", "/C", "node", "$file"]
I hope It'll help
I'm using windows and I created a New Build System with this content:
{
"cmd": ["node", "$file"],
"selector": "source.js",
"working_dir": "${project_path:${folder}}",
"path": "C:\\Program Files\\nodejs"
}
And after a ran a JavaScript file with sucessul inside Sublime.
My JavaScript file has this content:
var a = 10;
var b = 20;
var resultado = a + b;
console.log('resultado:', resultado);