lwsjs / local-web-server

A lean, modular web server for rapid full-stack development.
MIT License
1.22k stars 86 forks source link

Server has no output when executed by node exec() #162

Closed brachkow closed 3 years ago

brachkow commented 3 years ago

When I run server from cli everything works as expected, but if I run it from node.js it doesn't output anything.

const { exec } = require('child_process');
exec(
  `ws --directory ./dist/ --spa index.html --port 1111`,
  (error, stdout, stderr) => {
    if (error) {
      console.log(`error: ${error.message}`);
      return;
    }
    if (stderr) {
      console.log(`stderr: ${stderr}`);
      return;
    }
    console.log(`stdout: ${stdout}`);
  },
);
75lb commented 3 years ago

Use the API? https://github.com/lwsjs/local-web-server/wiki/API-reference

brachkow commented 3 years ago

@75lb but I want to use in combination with other cli tools

75lb commented 3 years ago

exec does not return the output until the process has ended - the ws process never ends (until manually stopped) as it's a server, so by design it must stay alive..

To capture the output of a running process, use spawn.

Closing, as this is not a bug with local-web-server.