Sublime Text 2 - making javascript build with Node.js

javascript, node.js, sublimetext2

Solution

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`.

Problem

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.

Original source

Related problems