Create an executable binary-like nar archive based on a static web application with an embedded HTTP server

December 13, 2014 ยท View on GitHub

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

Note for Windows users

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