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

143
Visualizações
How do I globally install a Node.js command-line script on the server?

As a prototype, I’ve written a simple Node.js command-line script which loads a .txt file and outputs the contents. I’ve read many articles which suggest that Node.js scripts are usually executed via the command-line and should be installed globally, so that’s the direction I’ve taken, even if there are other techniques.

For the sake of this query, my globally installed command is called my-prototype.

This all works fine on the desktop but I intend to host this prototype on a server, using Express.

How do I globally install my-prototype on the server and, if that’s possible, will I be able to execute it in the same way as in my local tests, as a child process?:

const { execSync } = require('child_process')
const output = execSync(`${process.execPath} my-prototype`)
console.log(output.toString())

I'm not entirely sure that globally installing command-line scripts is for use on a server and wonder whether that's for desktop use only.

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

0

If you need just output the contents, then you do not need a console, or rather: you only need it once, to run nodejs

const fs = require('fs');

const express = require('express');
const app = express();

//

app.get('/', async(req, res)=>{
    let fileContains = fs.readFileSync('./package.json', 'utf8');
    try{
        fileContains = JSON.parse(fileContains);
    }catch(e){}
    res.json(fileContains);
});

//

app.listen(80);

Also, read a little more about the pm2 module, it's very useful

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