How to Run Javascript Code in Sublime Text

Had many Hack Reactor students ask how I was running our daily toy problems straight from Sublime.

Disclaimer: This is not an interpreter and only allows you to see console.log() output. Alert() will not work. Besides that, it’s a quick way to test code. For those wanting an entire interpreter, try out SublimeREPL

Here’s how you can create a Javascript Sublime console:

  1. Open Sublime
  2. Go to ‘Tools’ on the tab bar
  3. Hover over ‘Build System’
  4. Click on ‘New Build System’

At this point, Sublime should have opened up a new tab for you, that looks like this:

Screen Shot 2014-06-17 at 9.57.29 AM

Delete the default text and paste this in:

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

Save it as node.

Now the next time you want to code in JS, go to Tools > Build System > Javascript.

To run your code, simply Command-B.

EDIT: If the above does not work, try this instead:

"cmd": ["/usr/local/bin/node", "$file", "$file_base_name"],
"working_dir": "${project_path:${folder}}",
"selector": "*.js"


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s