Mar 15

Adding a JS build-system to Sublime

Frustratingly, the Sublime Text editor doesn’t set up a build system for JavaScript the way it does for Ruby and some other languages. Fortunately, it’s an easy problem to fix. Assuming your JS interpreter is Node.js, these are the steps to set it up:

  • Open the Tools>Build System menu and select “new build system”
  • Name it Node, and a new file called node.sublime-build will be created.
  • Add the following data to it and save:
    • Restart Sublime
    • Select Node as the build system for your file and hit cmd + b to build from Sublime!

    Here’s an example JS file to run:

    Video walkthrough:

    For more Sublime goodies, see:
    Notes from my talk at Hack Reactor
    Strip trailing whitespace every time you save a file in Sublime Text

This entry was tagged , .
Bookmark the permalink.

17 Responses to Adding a JS build-system to Sublime

  1. Hippo says:

    Or you could simply use a Makefile. Sublime has support for make. ;-)

  2. Pingback: Adding a JS build-system to Sublime | Logic Mason | Lucas Kraus: Blog

  3. Bad Andy says:

    This works a treat, mate! Exactly what I was looking for. Cheers!

  4. Phil says:

    You have to save the file before it actually works, by the way…

  5. George says:

    This works great, but for some reason ST is not recognizing the build and using it automatically with .js files. I have to manually click into the build menu and change the build system to “Javascript” for it to work. Do you know why Automatic is not recognizing it as valid for .js files?

  6. George says:

    Nevermind, I actually figured it out. For “selector” you need to to use source.js instead of *.js. This fixed it at least on my machine.

  7. Steve says:

    I had a quick question on this.

    I am using OSX, and have node.js installed. After setting the build system up I save the file and run it, but it gives me this as the output:

    [Errno 2] No such file or directory
    [cmd: [u’node’, u’/Users/XXX/test.js’, u’test’]]
    [dir: /Users/XXX]
    [path: /usr/bin:/bin:/usr/sbin:/sbin]

    I copied the build system data exactly as it appears above. Any advice?

  8. Mai says:


    I know posted some time ago, but did you restart Sublime Text after you made the new build? Should work if you restart.

  9. Branislav Dinic says:

    Thx, node was not working on automatic build!

  10. Ron says:

    If you get Errno 2] No such file or directory
    then replace “node” with the path to node. ex: /usr/local/bin/node

  11. Some people have errors because path is in other dir, for this peoples use this:
    “cmd”: [“/usr/local/bin/node”, “$file”, “$file_base_name”],
    “working_dir”: “${project_path:${folder}}”,
    “selector”: “*.js”

  12. RJNY86 says:

    This worked for me

    “cmd”: [“node”, “$file”],
    “selector”: “source.js”

  13. Hector Mota says:

    Thanks man it works for me as the original

  14. Ana says:

    Thank you this one is working perfect for me.

  15. Pingback: Sublime Text에서 Javascript를 console로 돌리기 (자바스크립트 빌드하기) | Jay Jin, Programmer&Designer

  16. David says:

    For me this was enough as well:
    “cmd”: [“node”, “$file”],
    “selector”: “source.js”

    And using source.js instead of *.js really makes automatic detection.

    Solution for “No such file or directory” if you’re using nvm:

    Consider using nvm alternative to avoid this problem.

  17. Caim Astraea says:

    having some issues ? not working as i want it to …
    basically it needs a console.log for everything otherwise it won’t output
    something that would output when calling the function or variable directly .. without console.log or debug
    var a = ‘test’
    would output test.

Leave a Reply

Your email address will not be published. Required fields are marked *