9

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

angry kiwi
  • 10,730
  • 26
  • 115
  • 161
  • 1
    Solution to this problem http://stackoverflow.com/questions/12127711/sublime-build-how-to-stop-re-build-restart-node-app/12146477#12146477 – angry kiwi Aug 28 '12 at 02:52

7 Answers7

19

Cmd+Shift+P , search for "Nodejs::Default File Settings" ,it will open file "Node.js.sublime-settings". you'll see:

{
  // 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",

if the node path is not the same with above, find it and change to yours.

govo
  • 452
  • 6
  • 11
6

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:

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.

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.

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

James Harris
  • 61
  • 1
  • 2
4

To run nodejs on sublime text, install node package "node dev" then create a sublime text build, the code should look like this

{
  "cmd": ["node-dev", "$file"],
  "selector" : "source.js",
  "path" : "/usr/local/bin"
}

Now to run a nodejs app, go to menu->tools->build.

angry kiwi
  • 10,730
  • 26
  • 115
  • 161
  • I simply couldn't find such a plugin, "node dev". On the other hand, "nodejs" was installed without any problems. – khaz Nov 29 '22 at 16:20
1

What is going on is that you don't have the right PATH setup for your terminal.

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

export PATH=/usr/local/bin:$PATH

Here well you just have to look at the doc and 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

Look at this.

3on
  • 6,291
  • 3
  • 26
  • 22
0

On xubuntu, I made the build command in Nodejs.sublime-build explicity use the terminal:

"cmd": ["xfce4-terminal", "--command", "node $file"]

Nick Tulett
  • 66
  • 1
  • 2
0

Create a build sytem with this code:

{
   "cmd": ["node", "$file"],
   "selector" : "source.js"
}
chapuaAO
  • 1
  • 2
0

First make sure node is installed properly. Create new build system in sublime.

Tools > Build System > New Build System

It will create new file. replace the content with below comman

{
    "shell_cmd": "node $file"
}

save the file with extention .sublime-build

i.e. node.sublime-build

Now select build system in tools>build system>node (or whatever name you have set)

All set. open js file and hit ctrl+B or go Tools>build

CrackerKSR
  • 1,380
  • 1
  • 11
  • 29