Could somebody please point me in the right direction regarding the correct syntax of template literals ?
I have the following code (without template literals, works just fine) :
const dbUrl = 'localhost:27017/imgManager';
mongoose.connect('mongodb://' + dbUrl, { useNewUrlParser: true });
Now I'd like to put useNewUrlParser: true
in a variable :
const dbUrl = 'localhost:27017/imgManager',
dbOptions = 'useNewUrlParser: true';
mongoose.connect('mongodb://' + dbUrl, { dbOptions });
Doesn't work of course, mongoose.connect()
complains it has no dbOptions
:
$ node server.js
Server up: http://localhost:3300
the options [dbOptions] is not supported
I guess template literals are the way to go, but what's the right syntax ? I tried the following, but none works :
`mongoose.connect('mongodb://' + dbUrl, { ${dbOptions} });`
mongoose.connect(`mongodb://${dbUrl}, { ${dbOptions} }`);
mongoose.connect(`mongodb:\/\/${dbUrl}, { ${dbOptions} }`);
Any idea ?