0

here is the code:

const textIn = fs.readFileSync('./txt/input.txt', 'utf-8');

const textOut = 'this is the addition: ${textIn}, \nCreated on ${Date.now()}';

fs.writeFileSync('./txt/output.txt', textOut);

The content of the input.txt file is "hello world". What should happen is the content of the output.txt file should read "this is the addition: hello world 1614606057967.

but it reads...

this is the addition: ${textIn}

Created on ${Date.now()}

Any ideas why?

Code Stranger
  • 103
  • 1
  • 10
David
  • 55
  • 9

1 Answers1

3

According to these Mozilla docs, you need to enclose your string in backticks, not single quotes.

So you want:

const textOut = `this is the addition: ${textIn}, \nCreated on ${Date.now()}`;
Broots Waymb
  • 4,713
  • 3
  • 28
  • 51
  • @sunday - glad I could help! If this answer solved your issue, you could 'accept' it by clicking the checkmark near the upvote and downvote buttons to let others know this solution works. – Broots Waymb Mar 02 '21 at 14:11