Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda