1

I want build static resource server and websocket server into one exe file. using the open source package pkg. but official documentation have not example.

I have a web app, and a websocket server, for demo, it's should running in a pc without node.js environment. so, the best practice is building these to a .exe file.

 {
  "bin": "server/index.js",
  "pkg": {
    "assets": [
      "built/**/*"
    ]
  }
}

seem like good, but I don't know how to config websocket server. for terminal result, click the .exe file, it's have two window: one for static resource server other for websocket server

1
  • 1
    Thanks @Sunny for check language program and typo. Commented Oct 9, 2019 at 2:32

1 Answer 1

1

The problem was resolved.

Code:

// static resource server
app.use('/', express.static(__dirname + '/built/packaged/'));

app.get('/', function (req, res) {
  res.sendFile(__dirname + '/views/index.html', err => console.log(err));
});

then, embed the child_process for open a new websocket server:

const child_process = require('child_process');
child_process.exec(`node ./my-websocket.js --direction="C:/Users/"`, (err, stdout, 
  stderr) =>  { // ...});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.