Skip to content

Guide · Open source

How to use CoffeeScript: install, run and compile .coffee files

Updated · written with AI from the project's own documentation and checked against our catalogue data

CoffeeScript is a small programming language that compiles into JavaScript, which browsers and Node.js can run. It uses less punctuation than JavaScript and relies on indentation instead of braces and semicolons. This guide shows you how to install it, run and compile .coffee files, and decide whether it fits your work.

CoffeeScriptjashkenas/coffeescript · ★ 16.6k · MIT

Quick start

  1. 1Install Node.js. CoffeeScript needs Node.js. Install it first, then confirm npm is available in your terminal.
  2. 2Choose local or global install. Use the local command for a single project or the global command to run .coffee files from anywhere.
  3. 3Run the install command. Run npm install --save-dev coffeescript inside your project, or npm install --global coffeescript for a system-wide install.
  4. 4Write a .coffee file. Create a script using CoffeeScript's indentation-based syntax, with less punctuation than JavaScript.
  5. 5Execute the script. Run coffee /path/to/script.coffee to execute the file directly.
  6. 6Compile to JavaScript. Run coffee -c /path/to/script.coffee to translate the file into JavaScript.

What you need before you install CoffeeScript

CoffeeScript is installed with npm, so you need Node.js on your machine first. The project README describes CoffeeScript as a little language that compiles into JavaScript, which means you write .coffee source and the compiler produces JavaScript.

  • Node.js installed (required)
  • Basic understanding of JavaScript and Node.js, since the output runs in those environments

Install CoffeeScript for a project or globally

Choose a local install if you want the compiler tied to one project, or a global install if you want to run .coffee files from any folder. The README gives both commands.

  • Local, per project: adds CoffeeScript as a development dependency
  • Global: lets you execute .coffee files anywhere on your system
# Install locally for a project: npm install --save-dev coffeescript # Install globally to execute .coffee files anywhere: npm install --global coffeescript

Run a CoffeeScript file with the coffee command

Once CoffeeScript is installed globally, pass a .coffee file to the coffee command to execute it. Replace the path with the location of your script.

coffee /path/to/script.coffee

Compile a CoffeeScript file to JavaScript

To turn a .coffee file into JavaScript instead of running it, use the -c flag. The compiler converts your code into normal JavaScript that browsers or Node.js can run. The README does not cover where the output file is written, so check the documentation at coffeescript.org for details.

coffee -c /path/to/script.coffee

Where to find documentation and help

The README points to coffeescript.org for documentation, usage and examples, and to the GitHub issues page for feature requests and bug reports. The changelog is linked from the homepage, and the source repository is on GitHub.

  • Documentation and examples: https://coffeescript.org/
  • Report bugs or suggest features: https://github.com/jashkenas/coffeescript/issues
  • Source code: https://github.com/jashkenas/coffeescript.git

What people use it for

  • Maintaining an existing CoffeeScript codebase
  • Writing scripts with a terse, indentation-based syntax instead of braces and semicolons
  • Experimenting with language design or JavaScript compilers

Frequently asked questions

Is CoffeeScript free to use?

CoffeeScript is released under the MIT licence, as stated on the project page. The licence allows you to use it in your projects, subject to the terms of that licence.

What do I need to install CoffeeScript?

You need Node.js. CoffeeScript is installed with npm using either a local or global install command.

How do I run a .coffee file?

Install CoffeeScript globally with npm install --global coffeescript, then run coffee /path/to/script.coffee. The file is executed directly.

How do I compile CoffeeScript to JavaScript?

Use the coffee command with the -c flag, for example coffee -c /path/to/script.coffee. This translates the code into JavaScript.

Is CoffeeScript a good alternative to TypeScript?

For new projects that need mainstream JavaScript or TypeScript tooling, CoffeeScript is usually not the best choice, and the README does not describe current ecosystem support. TypeScript, Babel and Sucrase are comparable tools you could evaluate instead.

Can a beginner learn CoffeeScript without knowing JavaScript?

Not easily. CoffeeScript compiles to JavaScript and requires understanding JavaScript and Node.js to use effectively.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

CoffeeScript suits developers who maintain an existing CoffeeScript codebase, prefer indentation-based syntax, or enjoy language design experiments. If you are starting a new project that needs mainstream JavaScript or TypeScript tooling, or you are not comfortable with JavaScript and Node.js, consider TypeScript, Babel or Sucrase instead.

Install options & downloads