// Node-Webkit Tricks. // 1. Router. // You don't need a router in node-webkit, because you already have a better one: the file: protocol. // More: https://github.com/rogerwang/node-webkit/wiki/about-node.js-server-side-script-in-node-webkit#router // However the recommended way is not opening a new window or changing the `window.location`, you should just replace part of your page with ajax, like below. // In this way users won't have bad experience feeling refreshing the page, and the current javascript context is also kept. $('#main').load('views/user.html#zcbenz'); // 2. Template Engine. // The basic idea is: use the template engine to generate contents on the fly, and then append dynamic contents into the DOM. // More: https://github.com/rogerwang/node-webkit/wiki/about-node.js-server-side-script-in-node-webkit#template-engine // 3. Global Variable. // The `global` variable is also useful for apps that have multiple windows. // Every opened window will share a same `global`, so you can use it to transfer messages across different windows. // More: https://github.com/rogerwang/node-webkit/wiki/about-node.js-server-side-script-in-node-webkit#page-navigation-and-multiple-windows // 4. Livereload Node-Webkit on Changes. // https://github.com/rogerwang/node-webkit/wiki/Livereload-node-webkit-on-changes // Add this script tag to the end of your main file: var path = './'; var fs = require('fs'); fs.watch(path, function() { if (location) location.reload(); }); // 5. Play with Window. // https://github.com/rogerwang/node-webkit/wiki/Play-with-window window.open(URL,name,specs); // Create a new window. window.close(); // Close a window. window.focus(); // Focus on a window. window.blur(); // Blur on a window. window.resizeTo(width,height); // Resizes a window to the specified width and height. window.resizeBy(width,height); // Resizes a window by the specified amount. window.moveTo(x,y); // Moves a window's left and top edge to the specified coordinates. window.moveBy(x,y); // Moves a window a specified number of pixels relative to its current coordinates. // 6. Save Persistent Data in App. // It's very common to store persistent data in native apps, people usually do it by embedding external databases or manipulating plain text files. // In node-webkit, you have much better choices than that, you can use Web SQL Database, embedded databases, Web Storage (localStorage and sessionStorage) or Application Cache without headaches of any extra dependencies. // https://github.com/rogerwang/node-webkit/wiki/Save-persistent-data-in-app // 6.1. Web SQL Database. // http://html5doctor.com/introducing-web-sql-databases/ // 6.2. IndexedDB. (you might prefer using an abstraction, like PouchDB) // https://developer.mozilla.org/en-US/docs/IndexedDB // 6.3. PouchDB. // http://pouchdb.com/ // 6.4. EJDB. // https://github.com/Softmotions/ejdb // 6.5. NeDB. // https://github.com/louischatriot/nedb // 7. Crash Dump. // https://github.com/rogerwang/node-webkit/wiki/Crash-dump // 8. Transfer Objects Between Window and Node. // https://github.com/rogerwang/node-webkit/wiki/Transfer-objects-between-window-and-node // 9. Building Node-Webkit. // https://github.com/rogerwang/node-webkit/wiki/Building-node-webkit