Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Getting Started

jeffsu edited this page · 5 revisions

If you haven't installed js2 of some form, go here.

Now that you have it installed, lets get a "hello world" working. I'm going to use the command js2 to represent the flavor of js2 you have installed (js2-node, js2-ruby)

Create and input and output directory: mkdir src lib

Create a file called Hello.js2 in your input directory (src/Hello.js2) and paste this in:

class Hello {
  function world() {
    return "world";

var hello = new Hello();
console.log(;  // for ringo, use "system.print(" instead.

Now run: js2 compile src lib

Alternatively, you can setup a config file so that you don't have to specify the directories every time you want to run js2. To do so, create a js2.json file in the root or ./config directory of your project. Here is a sample js2.json file:

{ "src-dir": "./src", "target-dir": "./lib" }

Depending on your installation you can execute the compiled javascript from the command line: node lib/Hello.js ringo lib/Hello.js js2-ruby run lib/Hello.js

You can also set js2 to "watch" mode where it will periodically check for changed files and compile them for you: js2 watch src lib

See here for more instructions on how to run js2 on the command line.

Here are more specifics on the various flavors or js2:

Something went wrong with that request. Please try again.