An example of using a local webserver in NW.js
- Install Node.js & npm (comes with Node)
- Download or clone the repo
npm install
npm start
npm install
will download NW.js and Express to thenode_modules
folder.npm start
will Launch NW.js from your project's root.- NW.js will look at the
package.json
and 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.js
runs and starts up an Express server on port 3000. - Next NW.js will look at the
package.json
and see the"main"
set tohttp://localhost:3000
. Themain
is 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.html
file. - The last step that NW.js does is look at the
package.json
and see the"node-remote"
set tohttp://localhost:3000
. Thenode-remote
tells 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: