PyCharm 2016.2 Help

Running CoffeeScript

On this page:

Introduction

CoffeeScript code is not processed by browsers that work with JavaScript code. Therefore to be executed, CoffeeScript code has to be translated into JavaScript. This operation is referred to as transpilation and the tools that perform it are called transpilers.

For more details about transpilation in PyCharm, see the section Using File Watchers.

In either case, running CoffeeScript is supported only in the local mode. This means that PyCharm itself starts the Node.js engine and the target application according to a run configuration and gets full control over the session.

For more details about running Node.js applications, see Running and Debugging Node.js.

There are two approaches to running CoffeeScript in PyCharm:

  • Transpile the CoffeeScript code manually and then run the output JavaScript code as if it were a Node.js application.
  • Run the original CoffeeScript code through the NodeJS run configuration and have PyCharm transpile it on the fly.

Transpiling CoffeeScript manually and running the generated JavaScript code

  1. Transpile the CoffeeScript code into Javascript.
  2. Start creating a Node.js run configuration with the following mandatory settings:
    1. The Node.js engine to use. By default, the field shows the path to the interpreter specified on the Node.js page during Node.js configuration.
    2. In the Working directory field, specify the location of the files referenced from the starting CoffeeScript file to run, for example, includes. If this file does not reference any other files, just leave the field empty.
    3. In the Path to Node App JS File text box, specify the full path to the JavaScript file that was generated from the original CoffeeScript file during the transpilation.
  3. Save the configuration and click run.png on the toolbar.
  4. Proceed as while running a Node.js application.

Transpile CoffeeScript on the fly during run

  1. This mode requires that the register.js file, which is a part of the coffee-script package, should be located inside the project. Therefore you need to install the coffee-script package on the Node.js page locally, as described in Installing and Removing External Software Using Node Package Manager.
  2. Open the starting CoffeeScript file in the editor or select in the Project tool window and choose Create <CoffecScript_file_name> on the context menu. Alternatively, start creating a Node.js run configuration as described in Running and Debugging Node.js. In the Run/Debug Configuration: Node JS dialog that opens, specify the following mandatory settings:
    1. The Node interpreter to use. Select the relevant interpreter configuration or create a new one, see By default, the field shows the path to the interpreter specified on the Node.js page during Node.js configuration.

      For Linux and OS X, this setting is overridden by the Node.js from the path to the CoffeeScript transpiler executable file.

    2. In the Node parameters text box, type the following:
      --require coffee-script/register
    3. In the Working directory field, specify the working directory of the application. All references in the starting CoffeeScript file, for example, imports, will be resolved relative to this folder, unless such references use full paths.

      By default, the field shows the project root folder. To change this predefined setting, choose the desired folder from the drop-down list, or type the path manually, or click the Browse button browseButton.png and select the location in the dialog box, that opens.

    4. In the JavaScript file text box, specify the full path to the CoffeeScript file to run.

    Note that all the mandatory fields will be filled in automatically if you create a run configuration directly from the required CoffeeScript file.

  3. Save the configuration and click run.png on the toolbar.
  4. Proceed as while running a Node.js application.

See Also

Last modified: 23 November 2016