I see there are a ton of posts on this topic, but I didn't see any related to Express and my particular issue, which is:
import * as express from 'express';
import { Request, Response, Application } from 'express'; // <-- Error here
gives me an error (Module has no imported member for 'Request', 'Response' and 'Application').
I see that in node_modules there are the files request.js, response.js, and application.js listed in the /lib sub-directory. Based on the error trace, my guess is that Express is not checking in the /lib sub-directory. How can I force/guide the system to check in the /lib sub-directory when using import? (Or is that not the problem and there's another problem altogether?).
I tried import { Request, Response, Application } from 'express/lib', and import * as expressLib from 'express/lib and then import {Request, Response, Application } from expressLib, but neither of those worked.
Note: I have the following code below the imports . . . Because Request and Response are Object types, I assume they should be left in upper-case?
import * as express from 'express';
// import * as expressLib from 'express/lib'
import { Request, Response, Application } from 'express';
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
import * as jwt from 'jsonwebtoken';
import * as fs from "fs";
const app: Application = express();
app.use(bodyParser.json());
app.route('api/login')
.post(loginRoute);
const RSA_PRIVATE_KEY = fs.readFileSync('/demos/private.key');
export function loginRoute(req: Request, res: Response) {
const email = req.body.email,
password = req.body.password;
if (validateEmailAndPassword()) {
const userId = findUserIdForEmail(email);
const jwtBearerToken = jwt.sign({}, RSA_PRIVATE_KEY, {
algorithm: 'RS256',
expiresIn: 120,
subject: userId
});
// res.cookie("SESSIONID", jwtBearerToken, {httpOnly: true, secure: true});
res.status(300).json({
idToken: jwtBearerToken,
expiresIn: ""
})
} else {
res.sendStatus(401);
}
}