Giter Club home page Giter Club logo

nw-wrap's Introduction

nw-wrap

There are various open issues in node-webkit's github page regarging problems with stdin, stdout, stderr and argv. This module wraps nw to work arroung this issues.

Usage

There are two parts to it. node_modules/.bin/nw-wrap is what you execute as the parent process:

npm install nw-wrap
node_modules/.bin/nw-wrap args to node webkit and your app

Or, better yet, add it as a script in your package.json

"scripts": { "start": "nw-wrap args to node webkit and your app" }

and run it with npm start.

The other part, main.js, is what you get when you require('nw-wrap') from inside your appliaction. It returns an extended process object, with process.stdin connected to the nw-wrap executable's process.stdin via TCP.

nwwr = require('nw-wrap');
nwwr.stdin.pipe(nwwr.stdout);

For stdout and stderr the default behaviour is to pipe them to the parent process, but if stdout isn't working for you, or you want to clear up stderr for your own use, you can set the STDOUT_PORT, STDERR_PORT environment variables, and nw-wrap will connect the respective stream over TCP to the nw-wrap executable's corresponding standard stream.

For example, on linux stdout works just fine, but you might want to silence nw's stderr:

STDERR_PORT=7869 nw-wrap args to node webkit and your app

Note

Overriding the global.process with the return value of require('nw-wrap') breaks things, I don't know why. Doing so is probably a bad idea anyway. At first I did this so I could have a cli options parser like yargs pick process.argv up correctly. Fortunately, that's not necessary, since you can feed yargs any object, so I just pass it nwwr.argv.

Licence

MIT

nw-wrap's People

Contributors

spelufo avatar

Stargazers

Vladislav Alexeyev avatar ayapi avatar azu avatar

Watchers

James Cloos avatar  avatar  avatar

nw-wrap's Issues

Uncaught NodeError: Unknown stdin file type

Hello,
Using nwjs 0.25.3 with nw-wrap. Windows 10.

I'm calling this:

nwwr = require('nw-wrap');
nwwr.stdin.pipe(nwwr.stdout);

I am getting this error:

Uncaught NodeError: Unknown stdin file type              internal/process/stdio.js:105 
    at process.getStdin [as stdin] (internal/process/stdio.js:105:15)
    at Object.<anonymous> (D:\Downloads\nwjs-test-site\node_modules\nw-wrap\main.js:5:20)
    at Module._compile (module.js:648:30)
    at Object.Module._extensions..js (module.js:665:10)
    at Module.load (module.js:569:32)
    at tryModuleLoad (module.js:532:12)
    at Function.Module._load (module.js:524:3)
    at Module.require (module.js:592:17)
    at require (internal/module.js:11:18)
    at self.require (<anonymous>:11:26)

This also happens if I just call nwwr = require('nw-wrap');. I also tried setting STDOUT_PORT

nw-wrap errors

Hi,
I am trying to use your nw-wrap, but everytime I will get these errors.

Can you check?

$ node_modules/.bin/nw-wrap
events.js:154
      throw er; // Unhandled 'error' event
      ^

Error: spawn node-webkit ENOENT
    at exports._errnoException (util.js:856:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
    at onErrorNT (internal/child_process.js:344:16)
    at nextTickCallbackWith2Args (node.js:474:9)
    at process._tickCallback (node.js:388:17)
    at Function.Module.runMain (module.js:449:11)
    at startup (node.js:139:18)
    at node.js:999:3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.