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

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

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 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