Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure WebStorm / PhpStorm project so that JS code intelligence works well for Node.js projects?

Tags:

In WebStorm / PhpStorm / IDEA, there are quite a lot of code intelligence feature for JavaScript built in. However, when developing a Node.js application, including everything from node_modules complicates matters with things like "Navigate to file" (I don't want the IDE to offer me tens of package.jsons from node_modules folder, for example). But excluding the node_modules folder entirely has its own problems - there is no code completion etc.

So what's the "right" way to approach this in WebStorm? Should I include only some of the files from node_modules? Or exclude everything from there and somehow use the concept of project or global libraries?

Thanks.

like image 896
Borek Bernard Avatar asked Oct 03 '12 09:10

Borek Bernard


People also ask

Does WebStorm support NodeJS?

WebStorm integrates with Node. js providing assistance in configuring, editing, running, debugging, testing, profiling, and maintaining your applications. If you need Node.

Does PhpStorm support node JS?

Using Node.PhpStorm lets you run and debug Node. js applications using Node. js on Windows Subsystem for Linux.

Does PhpStorm support JavaScript?

With PhpStorm, you can develop modern web, mobile, and desktop applications with JavaScript and Node. js. PhpStorm also supports React, Angular, Vue. js, and other frameworks and provides tight integration with various tools for web development.

How do I run JavaScript in WebStorm?

To run a script, open it in the editor or select it in the Project tool window, and then select Run <script file name> from the context menu. WebStorm creates a temporary run/debug configuration of the type Node. js. To run a test, click the gutter icon next to it or press Ctrl+Shift+F10 .


1 Answers

To do this in the UI (tested from PyCharm 2.7.3, result shown in PhpStorm 6.0.3):

Add JavaScript Libraries

Add JavaScript Libraries

File → Settings
(Project Settings) → JavaScript → Libraries

[Add...] →

Name: node_modules
Visiblilty: [x] Current project
[Attach...]
{select project's node_modules folder}

{repeat for bower}

Exclude Folder from Project
Exclude Folder From Project

(Project Settings) → Project Structure
Right-click on folder → [Excluded]

To do this from project's .iml file:
Changing the project's .iml to the following:

<?xml version="1.0" encoding="UTF-8"?> <module type="WEB_MODULE" version="4">   <component name="NewModuleRootManager" inherit-compiler-output="true">     <exclude-output />     <content url="file://$MODULE_DIR$">       <excludeFolder url="file://$MODULE_DIR$/bower_components" />       <excludeFolder url="file://$MODULE_DIR$/node_modules" />     </content>     <orderEntry type="inheritedJdk" />     <orderEntry type="sourceFolder" forTests="false" />     <orderEntry type="library" name="node_modules" level="application" />     <orderEntry type="library" name="bower_components" level="application" />   </component> </module> 

Caused the editor to exclude node_modules and bower_components, but make them available for completion and library search

Tested in PyCharm, IntelliJ, and WebStorm.

like image 100
fncomp Avatar answered Dec 19 '22 02:12

fncomp