I’m trying to make a Javascript build system in Sublime Text 2 using Node.js. The problem is I don’t know where Node.js is installed on my mac (I installed it with mac installer and am running Mountain Lion) or how to properly assign a path variable to find it.
You use repeating to print repeating strings: const repeating = require('repeating'); console. log(repeating(100, 'unicorn '));
Create and save a JavaScript file (to execute a node interpreter, file needs to be saved), code some super amazing script and click Cmd + B (mac OS) or F7 (Windows). You can run this task manually from Tools > Build. Sublime Text should automatically run your script through appropriate build system.
Although Sublime Text comes with build systems for many other scripting languages, it does not come with a built-in Javascript build system. Many sources will tell you to create a . html page with a link to the . js file, then use a web browser console to see the results of your code.
If you haven't already, install Package Control in Sublime, then install the Nodejs
plugin. This should get you a lot farther than trying to build everything from scratch.
Once Nodejs is installed, open Preferences -> Package Settings -> Nodejs -> Settings - Default
and Settings - User
. Copy the entire contents of Default
to User
so you can edit it, then close Default
. (If you edit Default
, any changes will be overwritten on upgrade.) Change "node_command"
and "npm_command"
from false
to the full path returned by running which node
and which npm
from Terminal.app.
For example, if which node
returns /usr/local/bin/node
, and which npm
returns /usr/local/bin/npm
, then your settings file should look like this:
{
// 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": "/usr/local/bin/node",
// Same for NPM command
"npm_command": "/usr/local/bin/npm",
// as 'NODE_PATH' environment variable for node runtime
"node_path": false,
"expert_mode": false,
"ouput_to_new_tab": false
}
Save the file, and you should now be able to successfully use the commands in Tools -> Nodejs
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With