Whenever I run my code to search for a request and response from an express server, I encounter an issue where it cannot find declarations for the 'express' module. The error message transitions from
Could not find a declaration file for module 'express'.
to SyntaxError: Cannot use import statement outside a module
I attempted to use
const express = require('express')
. Then, I tried installing the types via npm. Now, I'm contemplating whether I need to create my own type definitions for my server.
import express, {request, response} from 'express';
const dictionary = {
"apple": "A round fruit with red or green skin and a white flesh.",
"banana": "A long curved fruit which grows in clusters and has soft pulpy flesh.",
"orange": "A spherical fruit with a tough bright reddish-yellow rind.",
};
const app = express();
app.use(express.json());
// Define an API endpoint to get a definition for a word
app.get('/:dictionary', function (req: request, res: response) {
console.log(req.params[dictionary]);
res.send();
});
app.listen(3000, () => {
console.log("Server listening on port 3000");
});
This represents my current code snippet.