I'm attempting to set up a mysql session storage in NestJS using Typescript. I've gone ahead and installed the necessary packages such as express-session, express-mysql-session, and @types/express-mysql-session. The code snippet below is compiling fine (main.ts file), however, upon running it, an error pops up in the console:
import { AppModule } from "./app.module";
import { env } from "./common/env";
import session from "express-session";
import MySQLStore from "express-mysql-session";
async function bootstrap() {
const app = await NestFactory.create(AppModule, {
cors: { credentials: env.ENABLE_CORS, origin: env.CLIENT_HOST },
});
//session store
const options = {
host: "db",
port: 3306,
user: env.DB_USER,
password: env.DB_PASSWD,
database: env.DATABASE,
checkExpirationInterval: 1000 * 60 * 60 * 2,
expiration: 1000 * 60 * 60 * 24,
};
const store = MySQLStore(session);
const sessionStore = new store(options);
app.use(
session({
secret: env.COOKIE_SECRET,
store: sessionStore,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24,
},
}),
);
await app.listen(env.PORT_BACKEND || 8080);
}
bootstrap();
The specific error can be viewed here.
Even attempting to use require instead of import doesn't seem to work, like so:
var MySQLStore = require('express-mysql-session')(session);
What would be the correct approach to make this setup work? Or perhaps there's a more suitable package available for this purpose?