Skip to content

Instantly share code, notes, and snippets.

@therealklanni
Last active August 29, 2015 14:01
Show Gist options
  • Save therealklanni/2a15360136b68abfeaac to your computer and use it in GitHub Desktop.
Save therealklanni/2a15360136b68abfeaac to your computer and use it in GitHub Desktop.
Sublime Text Node.js Buildtool

Sublime Text Node.js Build System

Allows you to execute JavaScript code in a REPL environment directly from Sublime Text.

This build system gives you access to everything you would expect to have access to with any typical Node script/application. For more advanced applications that expect some sort of user/client interactions, this may not work well (or at all), but it's great for testing snippets of code for instant feedback.

Save the Node.sublime-build file to Sublime's Packages/User folder. In order to run ("build") some JavaScript, it must be saved as a file somewhere. Then select "Node" as the build system and press ⌘B to run the active tab in Node.

Example

function head(xs) {
  return xs[0]
}

function tail(xs) {
  return xs.length ? xs.slice(1) : []
}

function sum(ns) {
  var n = head(ns), ns = tail(ns)
  return ns.length ? n + sum(ns) : n
}

console.log(sum([1,2,3,4,5]))
15
[Finished in 0.0s]
{
"cmd": ["/usr/local/bin/node", "$file"],
"selector": "*.js"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment