Sublime Text 2 JavaScript Console

I write a lot of Python and JavaScript, but there's one thing that always bothered me about the latter: having to test out snippets of code in the browser's console. All of that can change with a little help from an awesome text editor and Node.js

JavaScript Build System

Using a build system, you can run code from a file you are editing and see its output right inside Sublime. The only prerequisite is having Node.js installed. The following instructions cover adding a new build system.

 From the Tools menu choose Build System > New Build System:

SublimeText-New-Build-System.jpg

Paste in the following snippet, then save the file as Node.sublime-build in the User Packages folder. If you followed the first step and selected New Build System, then it should prompt you to save in this location already.

{
    "cmd": ["node", "$file"],
    "selector": "source.js"
}

With build configuration saved, you should see a new option under Tools > Build System:

SublimeText2-Node-Build-System.pjg

After selecting Node as your build system, you can use Cmd + B to run the JavaScript in an open file, provided you have saved your changes. The build system does not execute the code displayed in the window, it executes what is saved in the file currently.

SublimeText2-Build-Output.jpg

That's It

Now you can test out JavaScript snippets without ever leaving the comfort of the best text editor around. Enjoy!