### Example for Windows using set command Source: https://github.com/nwjs/nw.js/blob/main/docs/For Users/Advanced/Use Native Node Modules.md Full example for setting environment variables and installing native modules on Windows. ```Batchfile set PYTHON=C:\Python27\python.exe set npm_config_target=0.21.6 set npm_config_arch=x64 set npm_config_runtime=node-webkit set npm_config_build_from_source=true set npm_config_node_gyp=C:\Users\xxxxxxxxx\AppData\Roaming\npm\node_modules\nw-gyp\bin\nw-gyp.js npm install --msvs_version=2015 ``` -------------------------------- ### Running the Hello World App Source: https://github.com/nwjs/nw.js/blob/main/docs/For Users/Getting Started.md Command-line instructions to navigate to the application directory and run the NW.js application using the NW.js binary. ```bash cd /path/to/your/app /path/to/nw . ``` -------------------------------- ### index.html for Using Node.js API Example Source: https://github.com/nwjs/nw.js/blob/main/docs/For Users/Getting Started.md An HTML file that utilizes Node.js 'os' module to display the operating system platform within an NW.js application. ```html My OS Platform ``` -------------------------------- ### Loading a URL with the default app Source: https://github.com/nwjs/nw.js/blob/main/docs/References/Command Line Options.md Example of using the --url option to load a specific URL when starting NW.js. ```bash --url=http://nwjs.io ``` -------------------------------- ### Setup a stand-alone proxy server with latency Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/http-proxy/README.md Example demonstrating how to set up a proxy server with added latency. ```javascript var http = require('http'), httpProxy = require('http-proxy'); // // Create a proxy server with latency // var proxy = httpProxy.createProxyServer(); // // Create your server that makes an operation that waits a while // and then proxies the request // http.createServer(function (req, res) { // This simulates an operation that takes 500ms to execute setTimeout(function () { proxy.web(req, res, { target: 'http://localhost:9008' }); }, 500); }).listen(8008); // // Create your target server // http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); }).listen(9008); ``` -------------------------------- ### Object.observe example Source: https://github.com/nwjs/nw.js/wiki/Windows-Installer Example of observing changes to a DATA object using Object.observe. ```javascript Object.observe(DATA, function(){ self.onChange(DATA); }); ``` -------------------------------- ### Example of getting command line arguments Source: https://github.com/nwjs/nw.js/blob/main/docs/References/Command Line Options.md Demonstrates how to access command line arguments passed to the NW.js application, such as file paths. ```javascript nw.App.argv ``` -------------------------------- ### Install async module Source: https://github.com/nwjs/nw.js/wiki/Using-Node-modules Example of installing the 'async' module using npm. ```bash $ cd /path/to/your/app $ npm install async ``` -------------------------------- ### Basic Stand-alone Proxy Server Setup Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/http-proxy/README.md Example of setting up a basic stand-alone HTTP proxy server that forwards requests to a target server. ```javascript var http = require('http'), httpProxy = require('http-proxy'); // // Create your proxy server and set the target in the options. // httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(8000); // See (†) // // Create your target server // http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); }).listen(9000); ``` -------------------------------- ### Install npm packages and dependencies Source: https://github.com/nwjs/nw.js/wiki/How-to-run-node-webkit's-test-cases Installs nw-gyp globally, navigates to the test directory, and installs development dependencies. ```bash $ npm install -g nw-gyp $ cd src/content/nw/tests $ npm install -d ``` -------------------------------- ### Batch script for creating build versions Source: https://github.com/nwjs/nw.js/wiki/Windows-Installer A batch script configuration for an Inno Setup installer, defining application details, language settings, files to include, icons, and post-installation actions. ```batch AppUpdatesURL={#MyAppURL} DefaultDirName=C:\{#MyAppName} DefaultGroupName={#MyAppName} OutputDir=C:\path\to\installer OutputBaseFilename=Unity_v{#MyAppVersion} Compression=lzma SolidCompression=yes [Languages] Name: "brazilianportuguese"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl" [Tasks] Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked [Files] Source: "C:\path\to\dist\release\{#MyAppVersion}\bin\*"; DestDir: "{app}\bin"; Flags: ignoreversion Source: "C:\path\to\dist\release\{#MyAppVersion}\tools\*"; DestDir: "{app}\tools"; Flags: ignoreversion Source: "C:\path\to\dist\release\{#MyAppVersion}\Myapp.exe"; DestDir: "{app}"; Flags: ignoreversion [Icons] Name: "{group}\ {#MyAppName}"; Filename: "{app}\ {#MyAppExeName}" Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}" Name: "{commondesktop}\ {#MyAppName}"; Filename: "{app}\ {#MyAppExeName}"; Tasks: desktopicon [Run] Filename: "{app}\ {#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent ``` -------------------------------- ### example Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/mkdirp/readme.markdown Example of using mkdirp to create a directory asynchronously. ```javascript var mkdirp = require('mkdirp'); mkdirp('/tmp/foo/bar/baz', function (err) { if (err) console.error(err) else console.log('pow!') }); ``` -------------------------------- ### CLI Example Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/ecstatic/README.md Example of using ecstatic from the command line. ```bash ecstatic ./public --port 8080 ``` -------------------------------- ### Setup a stand-alone proxy server with custom server logic Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/http-proxy/README.md This example demonstrates how to proxy a request using a custom HTTP server and implement custom logic to handle the request. ```javascript var http = require('http'), httpProxy = require('http-proxy'); // // Create a proxy server with custom application logic // var proxy = httpProxy.createProxyServer({}); // // Create your custom server and just call `proxy.web()` to proxy // a web request to the target passed in the options // also you can use `proxy.ws()` to proxy a websockets request // var server = http.createServer(function(req, res) { // You can define here your custom logic to handle the request // and then proxy the request. proxy.web(req, res, { target: 'http://127.0.0.1:5060' }); }); console.log("listening on port 5050") server.listen(5050); ``` -------------------------------- ### CLI Header Example Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/ecstatic/README.md Example of setting headers via the CLI. ```bash $ ecstatic ./public -p 5000 -H 'Access-Control-Allow-Origin: *' ``` -------------------------------- ### Installing globally Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/http-server/README.md Installation via npm. ```bash npm install http-server -g ``` -------------------------------- ### install Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/mkdirp/readme.markdown Installation instructions for mkdirp using npm. ```bash npm install mkdirp ``` ```bash npm install -g mkdirp ``` -------------------------------- ### Installation Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/union/README.md Install the library using npm. You can add it to your package.json file as a dependancy ```bash $ [sudo] npm install union ``` -------------------------------- ### Repositories Example Source: https://github.com/nwjs/nw.js/wiki/Manifest-format Example structure for the 'repositories' field in the package.json. ```json "repositories": [ { "type": "git", "url": "http://github.com/example.git", "path": "packages/mypackage" } ] ``` -------------------------------- ### Using JS File as Main in package.json Source: https://github.com/nwjs/nw.js/blob/main/docs/For Users/Getting Started.md Example of setting a JavaScript file as the 'main' field in package.json, which allows for background initialization and manual window opening. ```javascript // initialize your app // and ... nw.Window.open('index.html', {}, function(win) {}); ``` -------------------------------- ### Choose Desktop Media Example Source: https://github.com/nwjs/nw.js/blob/main/docs/References/Screen.md Example demonstrating how to use Screen.chooseDesktopMedia to capture screen or window content. ```javascript nw.Screen.Init(); // you only need to call this once nw.Screen.chooseDesktopMedia(["window","screen"], function(streamId) { var vid_constraint = { mandatory: { chromeMediaSource: 'desktop', chromeMediaSourceId: streamId, maxWidth: 1920, maxHeight: 1080 }, optional: [] }; navigator.webkitGetUserMedia({audio: false, video: vid_constraint}, success_func, fallback_func); } ); ``` -------------------------------- ### index.html for Context Menu Example Source: https://github.com/nwjs/nw.js/blob/main/docs/For Users/Getting Started.md An HTML file demonstrating how to create a native context menu in an NW.js app using NW.js APIs. It includes JavaScript to create menu items and handle the 'contextmenu' event. ```html Context Menu

'Right click' here to show context menu.

``` -------------------------------- ### Serve the application with the SDK's web server Source: https://github.com/nwjs/nw.js/blob/main/docs/For Users/Advanced/Use NaCl in NW.js.md This command navigates to the getting_started directory within the Native Client SDK and starts a local web server to simulate a production environment for serving the application. ```bash cd pepper_$(VERSION)/getting_started make serve ``` -------------------------------- ### Proxy Configuration Examples Source: https://github.com/nwjs/nw.js/wiki/App Examples demonstrating various formats for configuring proxy settings in NW.js. ```javascript // // For example: // "http=foopy:80;ftp=foopy2" -- use HTTP proxy "foopy:80" for http:// // URLs, and HTTP proxy "foopy2:80" for // ftp:// URLs. // "foopy:80" -- use HTTP proxy "foopy:80" for all URLs. // "foopy:80,bar,direct://" -- use HTTP proxy "foopy:80" for all URLs, // failing over to "bar" if "foopy:80" is // unavailable, and after that using no // proxy. // "socks4://foopy" -- use SOCKS v4 proxy "foopy:1080" for all // URLs. // "http=foop,socks5://bar.com -- use HTTP proxy "foopy" for http URLs, // and fail over to the SOCKS5 proxy // "bar.com" if "foop" is unavailable. // "http=foopy,direct:// -- use HTTP proxy "foopy" for http URLs, // and use no proxy if "foopy" is // unavailable. // "http=foopy;socks=foopy2 -- use HTTP proxy "foopy" for http URLs, // and use socks4://foopy2 for all other // URLs. ``` -------------------------------- ### Getting the current window Source: https://github.com/nwjs/nw.js/wiki/Window Example of how to get the current window's Window object. ```javascript var win = gui.Window.get(); var new_win = gui.Window.open('https://github.com'); ``` -------------------------------- ### Window Resize Example Source: https://github.com/nwjs/nw.js/blob/main/test/browser/window-resizeto/index.html Demonstrates opening a new window, setting its properties, and resizing it. ```javascript main window button { -webkit-app-region: no-drag; } var gui = nw; var win; gui.Window.open('newpop.html', { x: 100, y: 100, width: 200, height: 300 }, function(w) { win = w; win.on('closed', function() { console.log('popup window is closed.'); win = null; }); win.on('loading', function() { console.log('start to load new window.'); }); win.on('loaded', function() { console.log('new window loaded.'); }); }); function takeSnapshot() { gui.Window.get().capturePage(function(img) { var image = win.window.document.getElementById('image'); image.src = img; }, 'png'); } gui.Window.get().on('close', function() { if (win != null) win.close(true); this.close(true); }); gui.Window.get().show(); ``` -------------------------------- ### script.iss Source: https://github.com/nwjs/nw.js/wiki/Windows-Installer This is an Inno Setup script used to create the Windows installer for the NW.js application. It defines application details, versioning, and installation parameters. ```innosetup #define MyAppName "MyAppName" #define MyAppVersion "{{version}}" #define MyAppPublisher "My Company, Inc." #define MyAppURL "http://my.url.to.app/" #define MyAppExeName "MyApp.exe" [Setup] AppId={{Unity@redeci.com.br} AppName={#MyAppName} AppVersion={#MyAppVersion} AppVerName={#MyAppName}v{#MyAppVersion} AppPublisher={#MyAppPublisher} AppPublisherURL={#MyAppURL} AppSupportURL={#MyAppURL} ``` -------------------------------- ### Quick Examples Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/async/README.md Demonstrates basic usage of async.map, async.filter, async.parallel, and async.series. ```javascript async.map(['file1','file2','file3'], fs.stat, function(err, results){ // results is now an array of stats for each file }); async.filter(['file1','file2','file3'], fs.exists, function(results){ // results now equals an array of the existing files }); async.parallel([ function(){ ... }, function(){ ... } ], callback); async.series([ function(){ ... }, function(){ ... } ]); ``` -------------------------------- ### Webview Event Listener Example Source: https://github.com/nwjs/nw.js/blob/main/test/sanity/issue6171-sdk-start-crash/index.html An example of an event listener for a webview element, handling permission requests. ```javascript // var wbv = document.getElementById('wbv'); // console.log(wbv); // var wbv2 = document.getElementById('wbv2'); // console.log(wbv2); var webview = document.getElementById('wbv'); //webview.addEventListener('permissionrequest', function (e) { //console.log("webview"+objCount+ ": permission - "+e.permission); // if (e.permission === 'loadplugin') { // if(userSession.allowPlugins) { // e.request.allow(); // } else { // // e.request.deny(); // } // } // if (e.permission === 'download') { // e.request.allow(); // } // // media // if (e.permission === 'media') { // e.request.allow(); // } // if (e.permission === 'geolocation') { // e.request.deny(); // } //}); ``` -------------------------------- ### Example Usage Source: https://github.com/nwjs/nw.js/wiki/Node-main This example demonstrates how to use the 'node-main' field to run a script on startup and interact with the DOM. ```html Hello World!

Hello World!

We are using node.js ``` -------------------------------- ### Example Usage Source: https://github.com/nwjs/nw.js/wiki/Node-main This example demonstrates how to use the 'node-main' field to run a script on startup and interact with the DOM. ```javascript (function(){ var i = 0; exports.callback0 = function () { console.log(i + ": " + window.location); window.alert ("i = " + i); i = i + 1; } })(); ``` -------------------------------- ### CoffeeScript with require Example Source: https://github.com/nwjs/nw.js/wiki/About-Node.js-server-side-script-in-nw.js This example demonstrates loading CoffeeScript files using the 'require' function after installing the 'coffee-script' module. ```html ``` -------------------------------- ### Example Usage Source: https://github.com/nwjs/nw.js/wiki/Node-main This example demonstrates how to use the 'node-main' field to run a script on startup and interact with the DOM. ```json { "name": "nw-demo", "node-main": "index.js", "main": "index.html" } ``` -------------------------------- ### mime.extension() Example Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/mime/README.md Get the default extension for a given mime type. ```javascript mime.extension('text/html'); // => 'html' mime.extension('application/octet-stream'); // => 'bin' ``` -------------------------------- ### Basic Usage and Commands Source: https://github.com/nwjs/nw.js/blob/main/test/sanity/issue6056-spawn-crash/node_modules/dblite/README.md Demonstrates how to initialize dblite, execute SQLite commands like '.show', and perform basic CRUD operations. ```javascript var dblite = require('dblite'), db = dblite('./db.sqlite'); // will call the implicit `info` console.log db.query('.show'); /* will console.log something like: echo: off explain: off headers: off mode: csv nullvalue: "" output: stdout separator: "," stats: off width: */ // normal query db.query('CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, value TEXT)'); db.query('INSERT INTO test VALUES(null, ?)', ['some text']); db.query('SELECT * FROM test'); // will implicitly log the following // [ [ '1', 'some text' ] ] ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/nwjs/nw.js/blob/main/docs/For Developers/Writing Documents for NW.js.md Command to start a local MkDocs server for previewing documentation. ```bash mkdocs serve ``` -------------------------------- ### mime.lookup() Example Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/mime/README.md Get the mime type associated with a file path. ```javascript var mime = require('mime'); mime.lookup('/path/to/file.txt'); // => 'text/plain' mime.lookup('file.txt'); // => 'text/plain' mime.lookup('.TXT'); // => 'text/plain' mime.lookup('htm'); // => 'text/html' ``` -------------------------------- ### evalNWBinModule Example Source: https://github.com/nwjs/nw.js/blob/main/docs/References/Window.md Example demonstrating how to use evalNWBinModule to load and execute a compiled binary module. ```html ``` -------------------------------- ### Screen API Sample Source: https://github.com/nwjs/nw.js/wiki/Screen Demonstrates how to initialize the Screen API, listen for various events like 'added', 'removed', 'orderchanged', 'namechanged', and 'thumbnailchanged', and start the desktop capture monitor. ```javascript gui.Screen.Init(); gui.Screen.DesktopCaptureMonitor.on("added", function (id, name, order, type) { //select first stream and shutdown var constraints = { audio: { //Note: Audio desktop capture only supported in Chromium in WindowsOS mandatory: { chromeMediaSource: "system", chromeMediaSourceId: id } }, video: { mandatory: { chromeMediaSource: 'desktop', chromeMediaSourceId: id, } } }; // TODO: call getUserMedia with contraints gui.Screen.DesktopCaptureMonitor.stop(); }); gui.Screen.DesktopCaptureMonitor.on("removed", function (id) { }); gui.Screen.DesktopCaptureMonitor.on("orderchanged", function (id, new_order, old_order) { }); gui.Screen.DesktopCaptureMonitor.on("namechanged", function (id, name) { }); gui.Screen.DesktopCaptureMonitor.on("thumbnailchanged", function (id, thumbnail) { }); gui.Screen.DesktopCaptureMonitor.start(true, true); ``` -------------------------------- ### Creating a package Source: https://github.com/nwjs/nw.js/wiki/MAS:-Uploading-the-binary Command to create a .pkg file for uploading the signed app. It requires setting environment variables for IDENTITY, APP_DIR, and APP_NAME. ```bash export IDENTITY=LK12345678 export APP_DIR=/path/to/yourapp/ export APP_NAME=yourapp cd $APP_DIR && productbuild --component "$APP_NAME.app" /Applications --sign $IDENTITY "$APP_NAME.pkg" ``` -------------------------------- ### Screen.chooseDesktopMedia Example Source: https://github.com/nwjs/nw.js/blob/main/test/sanity/screen-choosedekstopmedia/index.html This snippet shows how to initiate the screen media chooser and handle the stream. ```javascript Screen.chooseDesktopMedia startChoose(); function startChoose() { try { nw.Screen.Init(); var chooseId = nw.Screen.chooseDesktopMedia(["window","screen"], function(streamId) { var vid_constraint = { mandatory: { chromeMediaSource: 'desktop', chromeMediaSourceId: streamId, maxWidth: 1920, maxHeight: 1080 }, optional: [] }; navigator.webkitGetUserMedia({ audio: false, video: vid_constraint }, function(mediaStream) { var video = document.querySelector('video'); video.src = window.URL.createObjectURL(mediaStream); video.play(); }, function(err) { alert('failed'); console.log(err); }); }); // close it after 2s setTimeout(function() { try { nw.Screen.cancelChooseDesktopMedia(chooseId); writeSuccess(); } catch (e) { writeFailure(e); } }, 2000); } catch (e) { writeFailure(e); } } function writeSuccess() { var result = document.createElement('h1'); result.setAttribute('id', 'result'); result.innerHTML = 'success'; document.body.appendChild(result); } function writeFailure(e) { var result = document.createElement('h1'); result.setAttribute('id', 'result'); result.innerHTML = 'failure [' + e + ']'; document.body.appendChild(result); } ``` -------------------------------- ### Example of getting cookies for a webview Source: https://github.com/nwjs/nw.js/blob/main/docs/References/webview Tag.md This JavaScript snippet demonstrates how to retrieve all cookies for a specific URL within a webview context using the chrome.cookies API. ```javascript chrome.cookies.getAll({url:"http://docs.nwjs.io", storeId:webview.getCookieStoreId()}, console.log.bind(console)); ``` -------------------------------- ### Clipboard API Usage Example Source: https://github.com/nwjs/nw.js/wiki/Clipboard Demonstrates how to load the native UI library, get the system clipboard, read text from it, write text to it, and clear the clipboard. ```javascript // Load native UI library var gui = require('nw.gui'); // We can not create a clipboard, we have to receive the system clipboard var clipboard = gui.Clipboard.get(); // Read from clipboard var text = clipboard.get('text'); console.log(text); // Or write something clipboard.set('I love node-webkit :)', 'text'); // And clear it! clipboard.clear(); ``` -------------------------------- ### Shell API Examples Source: https://github.com/nwjs/nw.js/blob/main/docs/References/Shell.md Demonstrates how to use Shell.openExternal, Shell.openItem, and Shell.showItemInFolder. ```javascript // Open URL with default browser. nw.Shell.openExternal('https://github.com/nwjs/nw.js'); // Open a text file with default text editor. nw.Shell.openItem('test.txt'); // Show a file in parent folder with file manager. nw.Shell.showItemInFolder('test.txt'); ``` -------------------------------- ### Advanced Programmatic Usage with Process Control Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/opener/README.md Example demonstrating how to get the child process object returned by 'opener' and use 'unref' to allow the script to exit while the opened process continues. ```javascript var editor = opener("documentation.odt"); editor.unref(); // These other unrefs may be necessary if your OS's opener process // exits before the process it started is complete. editor.stdin.unref(); editor.stdout.unref(); editor.stderr.unref(); ``` -------------------------------- ### index.html for Hello World Source: https://github.com/nwjs/nw.js/blob/main/docs/For Users/Getting Started.md A standard HTML file that serves as the main content for the 'Hello World' NW.js application. It uses basic HTML tags to display a title and a heading. ```html Hello World!

Hello World!

``` -------------------------------- ### Setup a stand-alone proxy server with proxy request header re-writing Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/http-proxy/README.md This example shows how to proxy a request using a custom HTTP server that modifies the outgoing proxy request by adding a special header. ```javascript var http = require('http'), httpProxy = require('http-proxy'); // // Create a proxy server with custom application logic // var proxy = httpProxy.createProxyServer({}); // To modify the proxy connection before data is sent, you can listen // for the 'proxyReq' event. When the event is fired, you will receive // the following arguments: (http.ClientRequest proxyReq, http.IncomingMessage req, // http.ServerResponse res, Object options). This mechanism is useful when // you need to modify the proxy request before the proxy connection // is made to the target. // proxy.on('proxyReq', function(proxyReq, req, res, options) { proxyReq.setHeader('X-Special-Proxy-Header', 'foobar'); }); var server = http.createServer(function(req, res) { // You can define here your custom logic to handle the request // and then proxy the request. proxy.web(req, res, { target: 'http://127.0.0.1:5060' }); }); console.log("listening on port 5050") server.listen(5050); ``` -------------------------------- ### package.json for Hello World Source: https://github.com/nwjs/nw.js/blob/main/docs/For Users/Getting Started.md This is the manifest file for a basic NW.js application, written in JSON format. The 'main' field specifies the entry point HTML file, and the 'name' field provides a unique identifier for the app. ```json { "name": "helloworld", "main": "index.html" } ``` -------------------------------- ### Screen.chooseDesktopMedia Example Source: https://github.com/nwjs/nw.js/wiki/Screen Example demonstrating how to use Screen.chooseDesktopMedia to capture screen or window content and use it with navigator.webkitGetUserMedia. ```javascript var gui = require('nw.gui'); gui.Screen.Init(); // you only need to call this once gui.Screen.chooseDesktopMedia(["window","screen"], function(streamId) { var vid_constraint = { mandatory: { chromeMediaSource: 'desktop', chromeMediaSourceId: streamId, maxWidth: 1920, maxHeight: 1080 }, optional: [] }; navigator.webkitGetUserMedia({audio: false, video: vid_constraint}, success_func, fallback_func); } ); ``` -------------------------------- ### Package.json Test Script Example Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/opener/README.md An example of how to configure a 'test' script in package.json to use 'opener' for opening a local HTML test harness. ```json { "scripts": { "test": "opener ./test/runner.html" }, "devDependencies": { "opener": "*" } } ``` -------------------------------- ### Install with NPM (v0.111.3 and later) during install Source: https://github.com/nwjs/nw.js/blob/main/docs/For Users/Advanced/Use Native Node Modules.md Command to install native modules with a specific NW.js version. ```bash npm install --target=0.111.3 --disturl=https://dl.nwjs.io/ ``` -------------------------------- ### Get NW.js Version Source: https://github.com/nwjs/nw.js/wiki/Get-version-of-nw.js-in-app This code snippet shows how to get the version of NW.js using process.versions['node-webkit']. ```javascript process.versions["node-webkit"] ``` -------------------------------- ### install Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/mkdirp/node_modules/minimist/readme.markdown Installation command using npm. ```bash npm install minimist ``` -------------------------------- ### Bootstrap and Basic Operations Source: https://github.com/nwjs/nw.js/blob/main/test/sanity/issue6056-spawn-crash/node_modules/dblite/README.md Illustrates how to install and use dblite for basic database operations like querying databases and selecting data. ```javascript var dblite = require('dblite'), db = dblite('/folder/to/file.sqlite'); // ready to go, i.e. db.query('.databases'); db.query( 'SELECT * FROM users WHERE pass = ?', [pass], function (err, rows) { var user = rows.length && rows[0]; } ); ``` -------------------------------- ### Example index.html using require Source: https://github.com/nwjs/nw.js/wiki/Using-Node-modules An example HTML file demonstrating how to use 'require' to load the 'async' module. ```html test test should be here. ``` -------------------------------- ### Installation Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/portfinder/README.md Install the portfinder module using npm. ```bash $ [sudo] npm install portfinder ``` -------------------------------- ### Command Line Usage Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/opener/README.md Examples of using the 'opener' command line tool to open URLs, files, applications, and run commands. ```bash npm install opener -g opener http://google.com opener ./my-file.txt opener firefox opener npm run lint ``` -------------------------------- ### Installation Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/debug/README.md Install the debug module using npm. ```bash $ npm install debug ``` -------------------------------- ### Getting main version of node-webkit Source: https://github.com/nwjs/nw.js/wiki/Building-NW.js-(v0.12-and-below) Instructions for setting up the .gclient file for the main version of node-webkit. ```python solutions = [ { "name" : "src", "url" : "https://github.com/nwjs/chromium.src.git@origin/nw12", "deps_file" : "DEPS", "managed" : True, "custom_deps" : { "src/third_party/WebKit/LayoutTests": None, "src/chrome_frame/tools/test/reference_build/chrome": None, "src/chrome_frame/tools/test/reference_build/chrome_win": None, "src/chrome/tools/test/reference_build/chrome": None, "src/chrome/tools/test/reference_build/chrome_linux": None, "src/chrome/tools/test/reference_build/chrome_mac": None, "src/chrome/tools/test/reference_build/chrome_win": None, }, "safesync_url": "", }, ] ``` -------------------------------- ### Options Example Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/optimist/readme.markdown An example demonstrating the use of the .options() method to configure arguments. ```javascript var argv = require('optimist') .options('f', { alias : 'file', default : '/etc/passwd', }) .argv ; ``` -------------------------------- ### Install Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/url-join/README.md Install the url-join package using npm. ```bash npm install url-join ``` -------------------------------- ### Transactions Example Source: https://github.com/nwjs/nw.js/blob/main/test/sanity/issue6056-spawn-crash/node_modules/dblite/README.md Demonstrates how to use transactions for multiple queries. ```javascript db.query('BEGIN TRANSACTION'); for(var i = 0; i < 100; i++) { db.query('INSERT INTO table VALUES(?, ?)', [null, Math.random()]); } db.query('COMMIT'); ``` -------------------------------- ### Installation Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/requires-port/README.md Install the requires-port module using npm. ```bash npm install --save requires-port ``` -------------------------------- ### Create Proxy Server and Options Source: https://github.com/nwjs/nw.js/blob/main/test/node_modules/http-proxy/README.md Demonstrates how to create a proxy server instance using httpProxy.createProxyServer and passing an options object. ```javascript var httpProxy = require('http-proxy'); var proxy = httpProxy.createProxyServer(options); // See (†) ```