An example of using a local webserver in NW.js
- Install Node.js & npm (comes with Node)
- Download or clone the repo
npm installnpm start
npm installwill download NW.js and Express to thenode_modulesfolder.npm startwill Launch NW.js from your project's root.- NW.js will look at the
package.jsonand see the"node-main"set toserver.js. This will be the first thing NW.js runs and it runs this script in the "Node context" before a window is loaded. - The
server.jsruns and starts up an Express server on port 3000. - Next NW.js will look at the
package.jsonand see the"main"set tohttp://localhost:3000. Themainis usually set toindex.html, it tells NW.js what is the first page to load for your app's UI. Since the Express server is already running NW.js will go to that URL and Express will return theindex.htmlfile. - The last step that NW.js does is look at the
package.jsonand see the"node-remote"set tohttp://localhost:3000. Thenode-remotetells NW.js what URL's are allowed to run Node.js commands. With it pointing to the server you just started, your app can now run properly, accessing Node directly from the DOM. - From this point on you can create your app like you would in a regular browser. You can create folders for you images, styles, and scripts and link to them from your
index.html. You can also access any Node modules you've installed in the project.
For a more detailed step-by-step tutorial of using NW.js to create your first desktop app, click here: