I have a Node.js configuration file config.json as such:
{
"apiPrefix":"http://localhost:8080",
"serverPort":"8080",
"db":{
"name":"notes",
"host":"localhost",
"port":"27017"
}
}
When I try to connect to the MongoDB database:
import config from '../../etc/config.json';
export function setUpConnection(){
console.log(config.db);
mongoose.connect('mongodb://${config.db.host}:${config.db.port}/${config.db.name}');
}
But my server does not connect to the database, unless I write the URI address literally as follows:
mongoose.connect('mongodb://localhost:27017/notes');
What is wrong with my syntax ${} ? In console.log I see this
{ name: 'notes', host: 'localhost', port: '27017' }