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

241
Visualizações
Run function in script from command line (Node JS) using ES6 Modules

I just want to be able to run a specific function inside of a JS File ES6 Modules with Node.JS from the command line...

For example, I have a file called schedules.js which has the following function

export function name(params) {
  console.log('Hello World');
}

I want to be able to run that function by typing the following command in the command line:

node schedules.js name

The way I am trying to run that now, I just get nothing from as output

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use command line arguments. For getting command line arguments you can use process.argv. Maybe you can change your program something like that:

function name(params) {
  console.log("Hello World");
}
if (process.argv[2] === "name") {
  name("");
}

Now when you write "node schedules.js name" to your terminal your function will be called.

about 4 years ago · Juan Pablo Isaza Relatório

0

You don't need to export your function from the module. Just have nodeJs run the function but make sure you call your function in that module with the process.argv arguments that you pass in to it.

function schedules(name) {
  return name;
}

const name = process.argv[2];

console.log(schedules(name));

node schedules.js Lucas
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