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?

1
  • 1
    Use backticks(`) not inverted comma Commented Mar 1, 2021 at 14:16

1 Answer 1

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()}`;
Sign up to request clarification or add additional context in comments.

1 Comment

@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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.