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:
- Open the PhpStorm preferences pane and go to ‘plugins’.
- Click ‘Browse repositories…’.
- Search for NodeJS and install the plugin.
Setup NodeJS for your project
Next we need to setup NodeJS for your project:
- 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’).
- Setup the path to your Node Interpreter (to get this, open up a terminal and type which node .)
- Setup the Sources of Node.JS Core Modules:
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:
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:
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?
★ ★ ★ ★ ★