Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda