Search code examples
node.jsexpresswebstorm

Unresolved function or method sendFile(), express/nodejs using WebStorm


I'm using WebStorm, the code is working fine, but WebStorm is throwing a warning that it can't resolve sendFile() which is a part of expressjs. This is more of a nuisance than a problem.

let express = require("express")

let app = express();

app.get("/u/:id", function(req, res){
    let profileID = req.params.id;
    res.sendFile(__dirname + "/index.html")
});


app.listen(3000);

screenshot of some code


Solution

  • express methods are generated dynamically in runtime, so they can't be resolved during static code analysis. Installing TypeScript stubs should help to get methods resolved: put cursor on 'express' in let express = require('express');, hit Alt+Enter and choose Install TypeScript definitions for better type information to install typings - see https://www.jetbrains.com/help/webstorm/configuring-javascript-libraries.html#ws_jsconfigure_libraries_ts_definition_files

    enter image description here