Skip to content

Instantly share code, notes, and snippets.

@h2non
Last active August 29, 2015 14:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save h2non/ad21e0eda698e68e7743 to your computer and use it in GitHub Desktop.
Create an executable binary-like nar archive based on a static web application with an embedded HTTP server

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

@h2non
Copy link
Author

h2non commented Jul 9, 2014

Alternatively you could install too node-open and call it from the start command hook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment