Writing Node.JS code that is autocomplete friendly

Hi There,

I'm trying to get more information about writing NodeJS code that will work better with webstorm's indexing engine.

Even my simplest projects don't get indexed properly.

Could you please shed some light on what is the preferred coding style that the indexing engine would index properly? does the indexing engine evaluate some of the statement to associate values together? example - if I have two objects with constants contained in them and i merge them with lodash _.merge/object.assign - will it get evaluated by webstorm?

Another fresh example - context not identified:

class someClass{

this.mapObject = new Map();

].forEach((item) => { this.mapObject.set(item,'somevalue'); }, this);

Webstorm says that mapObject is an unresolved variable. even if i remove the ',this' context and use .bind(this) - still unresolved. 

I would appreciate if someone can please provide some best practices on how to write code that would be better crawled through and what we can expect from the indexing engine. I only found this in the context:


However it doesn't really say which are the better practices to get the code identified by the crawler - just that for external libraries I should download TypeScript community stubs. does this also mean that in order to get my code better identified I should also start writing TS stubs?

Any info would be appreciated!




this.mapObject is correctly resolved to me:

>if I have two objects with constants contained in them and i merge them with lodash _.merge/object.assign - will it get evaluated by webstorm?


No. WebStorm doesn't execute your code, types resolving is based on static analysis. So, to be able to detect that your objects are merged, it should provide special support for lodash _.merge/object.assign

If you have properties generated dynamically, you can't expect them being resolved during static analysis



OK. Thanks for clarifying.

Next problem I am experiencing:

Project 1 - lets assume package.json defines entry point as index.js


module.exports = {

 //key-value pairs defined here such as

key1: 'value1



Project 2 - defines project 1 as a dependency with a '*' version (installs latest).

inside project 2, lets assume index.js as a main entry point.





'use strict';

const path = require('path');
const fs = require('fs');
const codes = require('project1');

class SomeClass {

const someClassInstance = new SomeClass();
module.exports = {
someClassFunctionality: someClassInstance
codes: codes

Project 2 is also an NPM module.


When referencing project 2 from Project 3, 'codes' property does not show up on the autocomplete and is marked as unresolved.

const err = require('project2');

err.codes <-- undefined. shows up perfectly when debugging though.




Similar code works fine for me when all modules are 'local' (not installed via npm, but belong to same project):

So, WebStorm correctly resolves such dependencies.

May be, npm modules are not indexed for some reason (excluded, etc.)? Sample project would be helpful


they are not under the same project. these are different projects and they are installed via npm. packages are maintained via our own repo (private packages).

the node_modules folder was indeed excluded, but I removed the exclude flag but still it wouldn't help.

could you please open the appropriate ticket so we could follow up on this? I can send you the project files.




I can't open a ticket myself.:( Please create a new WebStorm support ticket at https://intellij-support.jetbrains.com/hc/en-us/requests/new?ticket_form_id=66731

Support tickets are private, so you can attach a project to it


Please sign in to leave a comment.