Attaching the sources of Node.js core modules

This is a cross-post from WebStorm & PhpStorm blog, originally posted by Sergey Simonchik.

When developing a Node.js application it can be convenient to have code completion, validation and debugging capabilities for Node core modules (fs, path, http, etc).

Unfortunately, these modules are compiled into the binary. So you have to download the Node.js source code and attach it to the project (all the required sources are located in the lib/ folder). But every time you decide to upgrade your Node installation, you have to repeat these steps – and don’t forget to detach previously attached sources to avoid confusion in code completion and navigation!

Well, from now on there’s an easier way to attach the Node.js sources to your project.

1) Open the Node.js settings dialog by clicking this icon on the toolbar:

Alternatively, you can open the Settings dialog (File | Settings or IntelliJ IDEA | Preferences) and select JavaScript | Node.js.

2) Specify the path to Node.js interpreter and the Node.js version will be determined automatically.

3) Click Configure and the following dialog opens:

4) Click the ‘Download and Configure’ button to download Node.js sources to the IntelliJ system local folder. A JavaScript library named “Node.js 0.6.12 Core Library” will be created from the extracted source files of core modules.

Now, to make it work the right way, define a usage scope for JavaScript library just created. By default the whole project will be added to the usage scope. You can tune the usage scope by clicking the ‘Edit usage scope’ hyperlink:

OK, now let’s try to code-complete methods from http core module:

Our work is done here.

Attaching the sources of Node core modules from the editor

An alternative way to attach these sources to the project is to invoke a quick-fix:

Please make sure you installed the latest NodeJS plugin from the plugin repository.

Develop your Node.js applications with pleasure!

Comments below can no longer be edited.

4 Responses to Attaching the sources of Node.js core modules

  1. Avatar

    Sean says:

    July 24, 2013

    IntelliJ 12 – Can’t put break point in Node.js in sub function that’s part of a library

    Please see this image: http://www.digitalsignage.com/temp/intellibug.png

    You can see that the break point is stopping outside the function and not inside the included Asyn library (which is the most common node.js librray) … this happens for all libraries, like ps (postgres) so we can’t debug inside included module node.js librraies…

    The only work around is to put the special keyword: debugger; and debugger will stop, but that is impossible to work with since if you are inside a long for loop, you can’t exit the debugger and have to F9 through all iterations, unless you remove the keyword debugger; and start debugging again, no fun 🙁

    Please fix this as node.js is VERY hot…


    Sean – http://DigitalSignage.com

  2. Avatar

    Sebastian says:

    April 19, 2015

    When I import a Node.JS project into IntelliJ, for example a very simple one that only consists of a single Javascript file and a package.json. Then IntelliJ does not automatically configure the core libraries for nodejs and its actually quite difficult to find these settings if you don’t exactly know where too look.

    For example in IntelliJ 14 when I go to File | Settings | Languages & Frameworks | Javascript | Libraries, then I have:

    * Node.js Core Modules
    * Node.js Globals

    It would be nice, if after the import in IntelliJ, these two would be activated automatically if IntelliJ detects that a NodeJS application is being imported. Or at least there should appear a notice at the top of the editor, same as it exists with git detection or for the spring detection.

  3. Avatar

    Albert says:

    June 15, 2016

    I installed the NodeJS plugin BUT I don’t have “Node.js v0.12.1 Core Modules”, “Node.js Globals” in Settings/Languages&Frameworks/JavaScript/Libraries. I tried to “Download” but both of them didn’t showed up in the list.

    • Avatar

      Simon says:

      April 13, 2017

      I have same problems too,

      Hope someone could help

Discover more