Sublime Text 3: Build System - node.js. NPM module not executing

For macOS, this worked for me on Sublime Text 3:

{
    "cmd": ["node","$file","$file_base_name"],
    "working_dir": "${project_path:${folder}}",
    "selector":"source.js"
}

Selector Note

My selector setting was:

"selector":"*.js"

and OdatNurd advised that:

The reason is that the selector is not correct; it doesn't match file names, it matches syntax scopes (i.e. it's based on the syntax in use regardless of file extension); changing it to source.js from *.js should get it working.


The command is incorrect for Sublime Text 3 :)

This is one example of running node as build system:

{
    "shell_cmd": "taskkill /F /IM node.exe & node ${file}"
}

Please note that the array-version doesn't work like in Sublime Text 2.


Following worked for me in Sublime Text 3 on Windows

  1. Tools -> Build System -> New Build System...
  2. Enter the below text in the new file
  3. Save the file as "nodejs.sublime-build"
{
  "shell_cmd": "node ${file}",
  "selector" : "source.js"
}

Prerequisite is to have node.js installed


Sublime text docs:

https://www.sublimetext.com/docs/build_systems.html

shell

Optional. If true, cmd will be run through the shell (cmd.exe, bash…)

Try to add "shell : true

{
  "cmd": ["node-dev", "$file"],
  "selector": "source.js",
  "windows" : {
     "shell": true
  }
}