Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 2 - making javascript build with Node.js [duplicate]

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.

like image 563
user3104891 Avatar asked Dec 15 '13 16:12

user3104891


People also ask

How do you repeat a node js code?

You use repeating to print repeating strings: const repeating = require('repeating'); console. log(repeating(100, 'unicorn '));

How do I create a JavaScript file in Sublime Text?

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.

Can you code JavaScript in Sublime Text?

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.


1 Answers

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.

like image 125
MattDMo Avatar answered Sep 29 '22 06:09

MattDMo