Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including js2coffee with all npm packages installed. Try it out:

var js2coffee = require("js2coffee")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

js2coffee v2.2.0

JavaScript to CoffeeScript compiler


Compile JavaScript into CoffeeScript.


This 2.0 release is a complete rewrite featuring a better parser (Esprima). See what's new in 2.0 for an overview of new features and consult the migration guide for info on updating from 0.x.


Available on npm and bower.

npm install --global js2coffee
js2coffee --help

npm version

Also available via CDN (window.js2coffee):

Command line

The command line utility accepts both filenames or stdin.

$ js2coffee file.js [file2.js ...]
$ cat file.js | js2coffee

JavaScript API

Available via npm (require('js2coffee')), or via CDN in the browser (as window.js2coffee):

result =;

result.code     // code string
result.ast      // transformed AST      // source map
result.warnings // array of warnings

Errors are in this format:

catch (e) {
  e.message       // "index.js:3:1: Unexpected INDENT\n\n   3   var\n   ---^"
  e.description   // "Unexpected INDENT"
  e.start         // { line: 1, column: 4 }
  e.end           // { line: 1, column: 10 }
  e.sourcePreview // '...'

Warnings are in this format:

result.warnings.forEach((warn) => {
  warn.description   // "Variable 'x' defined twice
  warn.start         // { line: 1, column: 4 }
  warn.end           // { line: 1, column: 9 }
  warn.filename      // "index.js"


  • Migration guide - guide for migrating from 0.x.

  • Hacking guide - want to contribute? here are tips to get you started.

  • AST format - technical description of the CoffeeScript AST format.

  • Special cases - a list of edge cases that js2coffee accounts for.

  • Compatibility mode - list of tweaks that compatibility mode (--compat) addresses.

  • Goals - outline of the project's goals.

  • Specs - examples of how JavaScript compiles to CoffeeScript.


js2coffee © 2012+, Rico Sta. Cruz. Released under the MIT License.
Authored by Rico Sta. Cruz with help from co-maintainers and contributors (list).



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free