·

photo credit: Scaffold via photopin (license)

How to enable autocompletion for NodeJS in PhpStorm

Tags: ,

Recently I’ve been tinkering a bit more with NodeJS, just to expand my horizon. I’ve done some simple things with NodeJS before, but since I work for 99% with PHP (WordPress, Magento) I (still) haven’t got a real use case yet to implement it on a larger scale.
Nevertheless – curious as I am – I started tinkering a bit more with NodeJS in my spare time. Since PhpStorm is my favorite IDE, I want to have the correct code autocompletion for NodeJS, just as I would have with PHP. In this article I’ll explain how to set this up.

Install the NodeJS plugin for PhpStorm

The first thing you need to do is install the NodeJS plugin for PhpStorm:

  1. Open the PhpStorm preferences pane and go to ‘plugins’.
  2. Click ‘Browse repositories…’.
  3. Search for NodeJS and install the plugin.

Screen Shot 2015-02-23 at 19.53.22

Setup NodeJS for your project

Next we need to setup NodeJS for your project:

  1. In the Project Settings, navigate to ‘Node.js and NPM’ (in the latest PhpStorm you can find this option under ‘Languages & Frameworks > Schemas and DTDs > Node.js and NPM’).
  2. Setup the path to your Node Interpreter (to get this, open up a terminal and type which node .)
  3. Setup the Sources of Node.JS Core Modules:

Screen Shot 2015-02-23 at 20.00.06
If you click on ‘Configure…’ you can either download the sources from the Internet (recommended) or point to a local archive or a directory. PhpStorm uses these files as a library for it’s autocompletion magic. When all is set is done, your Sources will look something like this:

Screen Shot 2015-02-23 at 09.00.06

Setup the usage scope

The last thing you need to do is setup the usage scope. This is the directory of your NodeJS project which you want PhpStorm to aid you with. Chances are that this needs to be the root of your project, but it could also be possible that your NodeJS project is in a subfolder of your project. Either way, you can set the NodeJS Library for each folder:

Screen Shot 2015-02-23 at 09.00.35
In above example, the folder ‘node’ makes use of the Node.js Globals and the Core Modules of Node.jS v0.12.0.

Visitors give this article an average rating of 3.9 out of 5.

How would you rate this article?

One thought on “How to enable autocompletion for NodeJS in PhpStorm”

  1. hub20xx says:

    Thank you Giel! I installed the nodejs module on my own in Phpstorm but I was surprised that it wasn’t enough to have autocompletion and suggestions up and running. Thanks to your post, I just got it running in no time! Thank you for sharing this! Take care!

Leave a Reply