Is there any way to have console-only, GUIless, windowless application with nw.js?
We have some internal utility originally made with App.js and recently converted to nw.js (formerly node-webkit). This tool consists of GUI app and console-only (integrated to build process) counterpart. App.js was able to execute any *.js like nodejs, in console, but in nw.js it seems mandatory for application to have some main *.html and window. Even when with node-main
in manifest it requires main
field to be present as well.
NW. js gives you the flexibility to freely choose whatever tools you'd like to work with. It's truly great to be able to create hybrid applications by focusing only on the web implementation you're already familiar with. Of course, NW.
NW. js makes Node. js available through the context of the embedded web browser, which means you can script JavaScript files that access both Node. js' API, as well as API methods related to the browser's JavaScript namespace, such as the WebSocket class.
NW. js uses a compiled version of Chromium with custom bindings, whereas Electron uses an API in Chromium to integrate Node.
Yes, just add "show": false
in package.json
{
"name": "My CLI App",
"main": "index.html",
"window": {
"show": false
}
}
Docs for package.json options
If you want you can make app.nw
package which will be open with node-webkit, so you don't need to ship big package.
You also can make a wrapper to run simple .js
files from terminal:
#!/bin/bash
# file nw-runner
BASEDIR=$(dirname $0)
/Applications/node-webkit.app/Contents/MacOS/node-webkit $BASEDIR/path/wrapper_app "$@"
So path/wrapper_app
will contain our application (package.json, index.html) and we will require specified file:
var args = require('gui').App.argv;
var path = require('path'), fs = require('fs');
var runable = path.relative(process.env.PWD, args[0]);
if (fs.existsSync(runable)) {
require(runable);
} else {
process.stdout.write("Can not not find file " + args[0]);
process.exit(1);
}
Then can run *.js file like this:
nw-runner ./my_app.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With