fs.appendFile(‘greetings.txt’, ‘Hello ${user.username}! You are ${notes.age}.’, function(err) {
if(err) {
console.log(‘Unable to write to file’);
}
});
when i run this, the output in greetings.txt file is:
Hello ${user.username}! You are ${notes.age}.
It should specify the users name and age. Where is my mistake in this?
Yeah, you need to be careful with this - using backquotes makes JS evaluate what’s inside the quotes, whereas normal quotation marks will not. It’s really easy to accidentally use normal quotes, which will just give you the literal string Hello ${user.username}! You are ${notes.age}. A syntax highlighter in the code editor should give you a clue: the literal string should be all one colour, whereas if you put it in backquotes it will highlight the stuff inside ${} in a different colour.