Haspemulator
Haspemulator

Reputation: 11308

How to import existing node.js module into Intellij IDEA?

I have an existing Node.js codebase, forked from GitHub. Now I want to import it to the Intellij IDEA 13 (ultimate version, which supports Node.js). When I simply try to import the project from the root folder of my existing code, IDEA doesn't add the 'lib' folder, where all the sources are. It should be simple, but I cannot figure it out. Any hints?

Upvotes: 33

Views: 34745

Answers (4)

If IntelliJ doesn't recognize a node.js project you should add the directory as a new module.

File -> New -> Module

Upvotes: -1

Haspemulator
Haspemulator

Reputation: 11308

Well, I've figured out a workaround, but not sure if it's the best solution. One can just create a new project of type "Web", and point it to the directory containing the module's sources. Then IDEA understands the whole structure, and you can create run configurations with Node.js.

In order to get additional Node features, like Intellisense for standard Node APIs, you'll still want to configure the project to be a Node project:

  1. Open the Preferences window
  2. Click Languages & Frameworks → Node.js and NPM
  3. In the section Coding Assistance you'll see if Node.js Core library is [not] enabled. If it is enabled, there's nothing more to do. If not click the Enable button
  4. Leave For the whole project checked, and click Configure
  5. The text should now change to Node.js Core library is enabled.

Upvotes: 70

toidiu
toidiu

Reputation: 965

Intellij 15 Professional Edition:

Import a new project -> Select the base folder of the project -> choose import form existing source.

When Intellij is done it wont look correct so do the following:

1) Project Structure CMD + ;

2) Go to Modules

3) Add a new module and select Node/Npm (if you dont have it then add a new plugin)

4) Point the source of the project to the base folder and click apply.

Upvotes: 4

Andreas Berheim Brudin
Andreas Berheim Brudin

Reputation: 2290

Another workaround:

If you have a version controlled Node app with no local changes, you could also create a new project of type "Node.js and NPM", point that to the directory. Then just use any standard settings.

After the project is created, you can just revert the files overwritten by IDEA (e.g. app.js and package.json), delete any new directories and files, and you will get the additional Node features in your project.

Upvotes: 4

Related Questions