Node.js require() code completion in WebStorm
NickName:Jordan Yim Ask DateTime:2016-09-24T19:14:10

Node.js require() code completion in WebStorm

In Node.js and WebStorm, we want to avoid using require() with relative file paths, e.g. require('../../../../../ugly/path/to/file')

We've tried using the include function from here: https://coderwall.com/p/th6ssq/absolute-paths-require

global.base_dir = __dirname;
global.abs_path = function(path) {
  return base_dir + path;
}
global.include = function(file) {
  return require(abs_path('/' + file));
}

global.include is basically require(), but uses an absolute path, eliminating the need for all the ../../../.

The problem is that WebStorm method hinting and autocompletion doesn't work with this. So is there any workaround that allows for WebStorm method completion AND absolute require() paths?

Copyright Notice:Content Author:「Jordan Yim」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/39675697/node-js-require-code-completion-in-webstorm

More about “Node.js require() code completion in WebStorm” related questions

Node.js require() code completion in WebStorm

In Node.js and WebStorm, we want to avoid using require() with relative file paths, e.g. require('../../../../../ugly/path/to/file') We've tried using the include function from here: https://code...

Show Detail

WebStorm code completion for node.js, express and EJS

I'm learning node.js just now and am using WebStorm 7.0.2 to edit the code (I use this IDE on a daily basis for my other hmlt5 + JS work, but apparently don't know it as much as I'd thought :-)). ...

Show Detail

WebStorm Intellisense/Code Completion Just Not Working

I'm struggling to get WebStorm Code Completion working and haven't been able to figure it out. I've been all over the forums and have tried everything suggested and would love some help. After

Show Detail

webstorm autocomplete for require(.json)

Webstorm is pretty smart when providing auto completion for node.js modules. unfortunatelly for some reason if the required module is a json file i.e var settings = require('./settings.json); it ...

Show Detail

WebStorm JSDoc class declaration for code completion with node.js modules

I'd like to know how to correctly use JSDoc in WebStorm 11 to mark classes and types in a node.js application to get code completion etc. Example: file A: function A(){ this.b = true; } A.

Show Detail

How to use AMD code completion with webstorm and requirejs?

I have something like this define(function(require) { var Router = require('./router'); var Backbone = require('backbone'); var Log = require('log'); ... Apparently Webs

Show Detail

I want to see automatic code completion and code documentation over webstorm

I am developing a project in node.js in webstorm. I don't see sufficient code completion like in Eclipse + Java. I also don't see any javascript documentation popping up with descriptions of the AP...

Show Detail

Enable code completion for node_modules in WebStorm

I'm new to WebStorm, and fairly new to Node development. I am working on an existing project, and want to have code completion for my node_modules. More specifically, I'm using Chai and WebStorm do...

Show Detail

WebStorm Code Completion

I am using generator-webapp and at app/index.html I don't have code completion for Bootstrap classes. In settings WebStorm recognises the Bootstrap dependency.

Show Detail

require keyword not appearing in code completion

I'm learning Node.js using Visual Studio Code (VSCode) v1.40.0 on a Mac Catalina and I'm not seeing the 'require' keyword appear in the code completion. Is there an extension or setting I need in o...

Show Detail