Await generates syntax error in express

When trying to initialise a new project for mongoose/express I get the following error:

const forest = require(‘forest-express-mongoose’);

const models = require(’./controllers/users’);

const connection = require(’./models/mongooseDatabase’);

app.use(await forest.init({

envSecret: process.env.FOREST_ENV_SECRET,

authSecret: process.env.FOREST_AUTH_SECRET,

objectMapping: models,

connections: { default: connection },

}));

app.use(await forest.init({
^^^^^

SyntaxError: missing ) after argument list

I have express 4.17 and mongoose 5.12

Expected behavior

I would expect the initialisation process to work as described in the documentation

Actual behavior

Getting the following error:

app.use(await forest.init({
^^^^^

SyntaxError: missing ) after argument list

Failure Logs

Please include any relevant log snippets, if necessary.

Context

Please provide any relevant information about your setup.

  • Package Version:
  • Express Version:
  • Sequelize Version:
  • Database Dialect:
  • Database Version:
  • Project Name:

Hello @pat,

The error

SyntaxError: missing ) after argument list

indicates something is wrong with the code syntactically, but the extract you shared is valid.
Is there something else in the file?

On another hand, it seems you are trying to use await forest.init at the top level, which is impossible.

Can you please try this one instead:

const Forest = require('forest-express-mongoose');
const models = require('./controllers/users');
const connection = require('./models/mongooseDatabase');

Forest.init({
    envSecret: process.env.FOREST_ENV_SECRET,
    authSecret: process.env.FOREST_AUTH_SECRET,
    objectMapping: models,
    connections: { default: connection },
}).then((forest) => app.use(forest))

this is the same code but using a promise instead of await/async

Regards