Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
NW.js Essentials

You're reading from  NW.js Essentials

Product type Book
Published in May 2015
Publisher
ISBN-13 9781785280863
Pages 192 pages
Edition 1st Edition
Languages

Table of Contents (17) Chapters

NW.js Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
1. Meet NW.js 2. NW.js Native UI APIs 3. Leveraging the Power of Node.js 4. Data Persistence Solutions and Other Browser Web APIs 5. Let's Put It All Together 6. Packaging Your Application for Distribution 7. Automated Packaging Tools 8. Let's Debug Your Application 9. Taking Your Application to the Next Level Index

Downloading and installing NW.js


Installing NW.js is pretty simple, but there are many ways to do it. One of the easiest ways is probably to run npm install nw from your terminal, but for the educational purposes of the book, we're going to manually download and install it in order to properly understand how it works.

You can find all the download links on the project website at http://nwjs.io/ or in the Downloads section on the GitHub project page at https://github.com/nwjs/nw.js/; from here, download the package that fits your operating system.

Tip

For example, as I'm writing this book, Node-Webkit is at version 0.12.0, and my operating system is Mac OS X Yosemite 10.10 running on a 64-bit MacBook Pro; so, I'm going to download the nwjs-v0.12.0-osx-x64.zip file.

Packages for Mac and Windows are zipped, while those for Linux are in the tar.gz format. Decompress the files and proceed, depending on your operating system, as follows.

Installing NW.js on Mac OS X

Inside the archive, we're going to find three files:

  • Credits.html: This contains credits and licenses of all the dependencies of NW.js

  • nwjs.app: This is the actual NW.js executable

  • nwjc: This is a CLI tool used to compile your source code in order to protect it

Tip

Before v0.12.0, the filename of nwjc was nwsnapshot.

Currently, the only file that interests us is nwjs.app (the extension might not be displayed depending on the OS configuration). All we have to do is copy this file in the /Applications folder—your main applications folder.

Tip

If you'd rather install NW.js using Homebrew Cask, you can simply enter the following command in your terminal:

$ brew cask install nw

If you are using Homebrew Cask to install NW.js, keep in mind that the Cask repository might not be updated and that the nwjs.app file will be copied in ~/Applications, while a symlink will be created in the /Applications folder.

Installing NW.js on Microsoft Windows

Inside the Microsoft Windows NW.js package, we will find the following files:

  • credits.html: This contains the credits and licenses of all NW.js dependencies

  • d3dcompiler_47.dll: This is the Direct3D library

  • ffmpegsumo.dll: This is a media library to be included in order to use the <video> and <audio> tags

  • icudtl.dat: This is an important network library

  • libEGL.dll: This is the WebGL and GPU acceleration

  • libGLESv2.dll: This is the WebGL and GPU acceleration

  • locales/: This is the languages folder

  • nw.exe: This is the actual NW.js executable

  • nw.pak: This is an important JS library

  • pdf.dll: This library is used by the web engine for printing

  • nwjc.exe: This is a CLI tool to compile your source code in order to protect it

Some of the files in the folder will be omitted during the final distribution of our application, but for development purposes, we are simply going to copy the whole content of the folder to C:/Tools/nwjs.

Installing NW.js on Linux

On Linux, the procedure can be more complex depending on the distribution you use. First, copy the downloaded archive into your home folder if you have not already done so, and then open the terminal and type the following command to unpack the archive (change the version accordingly to the one downloaded):

$ gzip -dc nwjs-v0.12.0-linux-x64.tar.gz | tar xf -

Now, rename the newly created folder in nwjs with the following command:

$ mv ~/nwjs-v0.12.0-linux-x64 ~/nwjs

Inside the nwjs folder, we will find the following files:

  • credits.html: This contains the credits and licenses of all the dependencies of NW.js

  • icudtl.dat This is an important network library

  • libffmpegsumo.so: This is a media library to be included in order to use the <video> and <audio> tags

  • locales/: This is a languages folder

  • nw: This is the actual NW.js executable

  • nw.pak: This is an important JS library

  • nwjc: This is a CLI tool to compile your source code in order to protect it

Open the folder inside the terminal and try to run NW.js by typing the following:

$ cd nwjs
$ ./nw

If you get the following error, you are probably using a version of Ubuntu later than 13.04, Fedora later than 18, or another Linux distribution that uses libudev.so.1 instead of libudev.so.0: otherwise, you're good to go to the next step:

error while loading shared libraries: libudev.so.0: cannot open shared object file: No such file or directory

Until NW.js is updated to support libudev.so.1, there are several solutions to solve the problem. For me, the easiest solution is to type the following terminal command inside the directory containing nw:

$ sed -i 's/udev\.so\.0/udev.so.1/g' nw

This will replace the string related to libudev, within the application code, with the new version. The process may take a while, so wait for the terminal to return the cursor before attempting to enter the following:

$ ./nw

Eventually, the NW.js window should open properly.

You have been reading a chapter from
NW.js Essentials
Published in: May 2015 Publisher: ISBN-13: 9781785280863
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}