After attempting to start the server, an error message is displayed:
this.mongo.connect('mongodb://localhost:27017/tsnode', { ^ TypeError: Cannot read property 'connect' of undefined
import express from 'express';
import mongoose from 'mongoose';
import cors from 'cors';
class App {
public express: express.Application;
public mongo: mongoose.Mongoose;
constructor() {
this.express = express();
this.database();
this.middlewares();
this.routes();
}
private middlewares(): void {
this.express.use(express.json());
this.express.use(cors());
}
private database(): void {
this.mongo.connect('mongodb://localhost:27017/tsnode', {
useUnifiedTopology: true,
});
}
private routes(): void {
this.express.get('/', (req, res) => res.send('Hello World!'));
}
}
export default new App().express;