How can I start a Meteor instance before launching a node-webkit?

后端 未结 1 1050
天命终不由人
天命终不由人 2021-01-06 08:06

I have developed a Meteor app. I would like to package this app in the node-webkit app runtime for Chromium. I need the Meteor server process to run locally. How wou

1条回答
  •  遥遥无期
    2021-01-06 08:22

    First Bundle your meteor app meteor build --directory /your/node-webkit/project/ and use this code to start your app. But, packaging Meteor with node-webkit can be a little bit more complicated. First, you'll need a mongodb server running on your client computer or somewhere the client can connect anytime.

    var path = require('path');
    var child_process = require('child_process');
    
    // change these
    var PORT = 9000;
    var ROOT_URL = 'http://localhost:'+PORT;
    var MONGO_URL = 'mongodb://localhost:27017/my_app_db';
    var NODE_BIN = '/usr/local/bin/node';
    
    // install npm dependencies
    var options = {cwd: path.resolve(__dirname, 'bundle/programs/server/')};
    var installNpm = child_process.exec('npm install', options, onNpmInstall);
    
    function onNpmInstall (err, stderr, stdout) {
      if(err) throw new Error('could not install npm dependencies');
    
      // start Meteor
      var options = {
        env: {PORT: PORT, MONGO_URL: MONGO_URL, ROOT_URL: ROOT_URL},
        cwd: __dirname
      };
    
      var proc = child_process.spawn(NODE_BIN, ['bundle/main.js'], options);
      proc.on('close', function (code) {
        console.log('Meteor exited with code ' + code);
      });
    }
    

    You must remove mongo related smart packages if you want a 100% client-side application.

    0 讨论(0)
提交回复
热议问题