Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get intellisense for express.js in vscode

I have tried installing type definitions with:

My code is in server.js javascript file.

npm install @types/express

But still it doesn't seem to give intellisense for app after instantiating express .

But when I use express like this :

app = express() ;

app.listen(8000) ;

I am not getting the codecompletion or intellisense for app instance of express.

How to fix this ?

like image 274
Natesh bhat Avatar asked Dec 18 '17 07:12

Natesh bhat


Video Answer


2 Answers

import this code:

/** @type {import("express").RequestHandler} */

like image 127
Vince Avatar answered Oct 17 '22 16:10

Vince


Add this JsDoc comment to your controllers:

/** @type {import("express").RequestHandler} */
exports.myController = (req, res) => {
  // biz logic. ( here you would get intelliscence on req, res objects )
  const { id } = req.query;
  const { data } = req.body;
  res.status(200).json({data});
}

like image 34
Rohit Kaushal Avatar answered Oct 17 '22 14:10

Rohit Kaushal