Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 927
Haspemulator Avatar asked Dec 09 '13 16:12

Haspemulator


People also ask

How do I import an existing module into IntelliJ?

Import an existing moduleFrom the main menu, select File | New | Module from Existing Sources. In the dialog that opens, specify the path the . iml file of the module that you want to import, and click Open. By doing so, you are attaching another module to the project without physically moving any files.

How do I load an existing project in IntelliJ?

Otherwise, from the main menu, select File | New | Project from Existing Sources. In the dialog that opens, select the directory in which your sources, libraries, and other assets are located and click Open. Gradle or Android Gradle: select the necessary build tool and click Finish.

Can I run NodeJS in IntelliJ?

IntelliJ IDEA lets you run and debug Node. js applications using Node. js on Windows Subsystem for Linux. You can choose Node.


2 Answers

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.
like image 180
Haspemulator Avatar answered Sep 21 '22 06:09

Haspemulator


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.

like image 44
Andreas Berheim Brudin Avatar answered Sep 19 '22 06:09

Andreas Berheim Brudin