AppCode 2019.1 Help

Node.js

Node.js is a lightweight runtime environment for executing JavaScript on the server side. AppCode integrates with Node.js providing assistance in configuring, editing, running, debugging, testing, profiling, and maintaining your applications.

If you need Node.js only for managing npm packages or running JavaScript linters, build tools, test frameworks, etc., just install Node.js. If you follow the standard installation procedure, in most cases AppCode detects Node.js itself.

To use Node.js as a runtime for your application, you need to configure it as a local or remote interpreter. To do this, install the NodeJS plugin on the Plugins page as described in Managing plugins.

Configuring a local Node.js interpreter

  1. In the Preferences dialog (⌘,), go to Languages and Frameworks | Node.js and NPM.

  2. On the Node.js and NPM page, that opens, click the Browse button next to the Node Interpreter list.

  3. In the Node.js Interpreters dialog that opens with a list of all the currently configured interpreters, click the Add button on the toolbar. In the dialog box that opens, choose Add Local on the context menu and choose the local installation of Node.js, then click OK. You return to the Node.js Interpreters dialog where the Node interpreter read-only field shows the path to the chosen interpreter.

  4. In the Package manager field, choose the package manager (npm or Yarn) to use in the current project, see Configuring a package manager for a project for details.

When you click OK, you return to the Node.js and NPM page where the Node interpreter field shows the new interpreter.

Using a system Node.js version

With AppCode, you can set the default system node alias as your project’s Node.js version. This means that if you install a new node version and make it the default in your system, all the tools and run configurations in AppCode where this system alias is specified in the Node.js interpreter field will use this newer version.

  1. In the Preferences dialog (⌘,), go to Languages and Frameworks | Node.js and NPM.

  2. From the Node interpreter drop-down list, choose node.

    ws_node_alias.png

  3. Specify this new Node.js interpreter where applicable, e.g. in you run/debug configurations or settings of specific tools.

Using Node.js on Windows Subsystem for Linux

AppCode lets you run and debug Node.js applications using Node.js on Windows Subsystem for Linux. You can choose Node.js on WSL as the default interpreter for the current project or you can configure and use this node version in a Node.js Run/Debug configuration.

To configure Node.js on WSL as the default project node interpreter

  1. In the Preferences dialog (⌘,), go to Languages and Frameworks | Node.js and NPM.

  2. Click the Browse button next to the Node Interpreter field, in the Node.js Interpreters dialog that opens, click the Add button, and then select Add WSL from the list.

    Configuring Node.js on WSL as the default project node interpreter
  3. In the Add WSL Node Interpreter dialog that opens, select the Linux distribution you’re using and specify the path to Node.js.

    Specifying the Linus distribution and the path to Node.js

Creating a Node.js application

If you have no application yet, you can generate a AppCode project with Node.js-specific structure from a template or create an empty AppCode project and configure Node.js in it as described in Starting with an existing Node.js application below.

To create a new Node.js application

  1. Select File | New Project from the main menu or click Create New Project on the Welcome screen. The New Project dialog opens.

  2. In the left-hand pane, choose Node.js to create a basic Node.js application or Node.js Express App to create an Express application.

  3. In the right-hand pane, specify the project folder, the Node.js interpreter, the package manager (npm or Yarn, see npm and Yarn for details).

    For Node.js Express app, specify the version of express-generator and select the template language and the Style Sheet language to use.

  4. When you click Create, AppCode downloads the necessary dependencies and enables code completion for them as well as for the Node.js core APIs, see Configuring node_modules library and Configuring Node.js Core library for details.

    For Node.js Express, AppCode creates a run/debug configuration of the type Node.js with default settings and generates a basic Node.js Express - specific directory structure.

    For Node.js, AppCode just runs the npm init command to generate a package.json file.

To create an empty AppCode project

  1. Select File | New Project from the main menu or click Create New Project on the Welcome screen. The New Project dialog opens.

  2. In the left-hand pane, choose Empty Project. In the right-hand pane, specify the application folder and click Create.

Starting with an existing Node.js application

If you are going to continue developing an existing Node.js application, open it in AppCode, configure Node.js in it, and download the required dependencies.

To open the application sources that are already on your machine

  • Click Open on the Welcome screen or select File | Open from the main menu. In the dialog that opens, select the folder where your sources are stored.

To check out the application sources from your version control

  1. Click Check out from Version Control on the Welcome screen or select VCS | Check out from Version Control from the main menu.

  2. Select your version control system from the list.

  3. In the VCS-specific dialog that opens, type your credentials and the repository to check out the application sources from.

To download the project dependencies, do one of the following:

  • In the embedded Terminal (⌥F12), type:

    npm install

  • Select Run 'npm install' from the context menu of the package.json file in your project root.

To configure Node.js in a project

  1. In the Preferences dialog (⌘,), go to Languages and Frameworks | Node.js and NPM.

  2. In the Node Interpreter field, specify the default Node.js interpreter for the current project. AppCode will automatically use it every time you select the Project alias from Node Interpreter lists when creating run/debug configurations or configuring Node.js-dependent tools, for example, Prettier or Yeoman.

    Choose the interpreter from the drop-down list or from the dialog that opens when you click the Browse button. If you choose node, the system Node.js version is used.

Last modified: 18 April 2019

See Also