Old post, but in case anyone else is trying to do this...
I haven't had any luck installing express or other server libraries, but you can start one using @skpm/child_process
, spawn
and a Ruby one-liner:
const { spawn } = require('@skpm/child_process')
const PORT = 8080;
const PATH = ".";
export function startServer() {
console.log("Starting server...")
const ls = spawn("ruby", ["-run", "-ehttpd", PATH, "-p" + PORT]);
ls.stdout.on("data", data => {
console.log(`stdout: ${data}`);
});
ls.stderr.on("data", data => {
console.log(`stderr: ${data}`);
});
ls.on('error', (error) => {
console.log(`error: ${error.message}`);
});
ls.on("close", code => {
console.log(`child process exited with code ${code}`);
});
}