nar webapp howto
Create a fully self-contained executable of a web application with an embedded HTTP server using nar
Install nar
as global package (you must have node.js
already installed in your system)
$ npm install -g nar
Create a new directory for your application and switch into it
$ mkdir my-app && cd my-app
Create the package.json
manifest of your application
{
"name": "my-app",
"version": "0.1.0",
"scripts": {
"start": "node ./node_modules/.bin/http-server app -p 8080"
},
"dependencies": {
"http-server": "^0.6.1"
}
}
Install node dependencies
$ npm install
Create the app folder and copy your web application static assets into it (CSS, JS, images...)
$ mkdir app
Create the nar
executable application
$ nar create -e
Optionally you can create the executable for multiple target OS
$ nar create -e --os linux|darwin|sunos
This process will generate a file like: my-app-0.1.0-linux-x64.nar
Now you can distribute this file
nar
executables cannot run in Windows, however you can create them for other OS.
You just need to specify the target OS flag like --os linux --arch x64
Running the app will be as simple as
$ chmod +x my-app-0.1.0-linux-x64.nar
$ ./my-app-0.1.0-linux-x64.nar start
Finally, your application is working. You can see it in action from a web browser
Alternatively you could install too node-open and call it from the start command hook