Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
Convert plain text into a template literal in javascript

Hope everyone doing great.

Actually, I'm trying to build an email automation tool where a user can send an email to multiple recipients and I want to implement such a functionality where the user can write email body in a text file e.g Hello ${name}, how are you ${name} and the program simply read body from this text file and replace ${name} with the names of the recipients that comes from .csv file.

Problem: The problem I face here is instead of replacing ${name} with names it simply sends the exact text read from the file for example Instead of Hello John, How are you it sends Hello ${name}, How are you. So, Is there any way to convert plain text into JS template literal or any other way to do this task? It would be a great help.

Thanks in Advance

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can try vm module:

import vm from 'vm';

const context = {
  name: 'Jane',
};
vm.createContext(context);

const templateFileContent = 'Hello ${name}, how are you ${name}';
const interpolatedString = vm.runInContext(`\`${templateFileContent}\``, context);

console.log(interpolatedString);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!