如何将现有的 node.js 模块导入 Intellij IDEA?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20476113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to import existing node.js module into Intellij IDEA?
提问by Haspemulator
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?
我有一个现有的 Node.js 代码库,从 GitHub 分叉出来。现在我想把它导入Intellij IDEA 13(终极版,支持Node.js)。当我只是尝试从现有代码的根文件夹导入项目时,IDEA 不会添加所有源代码所在的“lib”文件夹。它应该很简单,但我无法弄清楚。任何提示?
回答by Haspemulator
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.
好吧,我想出了一个解决方法,但不确定它是否是最好的解决方案。只需创建一个“Web”类型的新项目,并将其指向包含模块源的目录。然后IDEA理解了整个结构,你就可以用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:
为了获得额外的 Node 功能,比如标准 Node API 的 Intellisense,您仍然需要将项目配置为 Node 项目:
- Open the Preferenceswindow
- Click Languages & Frameworks → Node.js and NPM
- In the section Coding Assistanceyou'll see if Node.js Core library is [not] enabled. If it isenabled, there's nothing more to do. If not click the Enablebutton
- Leave For the whole projectchecked, and click Configure
- The text should now change to Node.js Core library is enabled.
- 打开首选项窗口
- 单击语言和框架 → Node.js 和 NPM
- 在Coding Assistance部分,您将看到Node.js Core 库是否 [not] enabled。如果已启用,则无需执行任何操作。如果没有点击启用按钮
- 为整个项目保留选中状态,然后单击配置
- 文本现在应该更改为Node.js Core library is enabled。
回答by Andreas Berheim Brudin
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.
如果您有一个没有本地更改的版本控制的 Node 应用程序,您还可以创建一个类型为“Node.js 和 NPM”的新项目,将其指向目录。然后只需使用任何标准设置。
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.
项目创建完成后,您只需恢复IDEA覆盖的文件(例如app.js和package.json),删除任何新目录和文件,您将在项目中获得额外的Node功能。
回答by toidiu
Intellij 15 Professional Edition:
Intellij 15 专业版:
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:
完成 Intellij 后,它看起来不正确,因此请执行以下操作:
1) Project Structure CMD + ;
1) 项目结构 CMD + ;
2) Go to Modules
2)转到模块
3) Add a new module and select Node/Npm (if you dont have it then add a new plugin)
3)添加一个新模块并选择Node/Npm(如果你没有,那么添加一个新插件)
4) Point the source of the project to the base folder and click apply.
4) 将项目源指向基础文件夹,然后单击应用。

