Skip to content

pmq20/node-packer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js Compiler

Ahead-of-time (AOT) Compiler designed for Node.js, that just works.

GitHub version

Terminal simulation of a simple compilation

Features

  • Works on Linux, Mac and Windows
  • Creates a binary distribution of your application
  • Supports natively any form of require, including dynamic ones (e.g. `require(myPath + 'module.js')
  • Supports any module, including direct download and compilation from npm
  • Native C/C++ modules fully supported
  • Features zero-config auto-update capabilities to make your compiled project to stay updated
  • Open Source, MIT Licensed

Development Status

Master CI RAM CI Black‑box CI
Windows status status status
macOS / Linux status Status Status

Get Started

It takes less than 5 minutes to compile any project with node-compiler.

You won't need to modify a single line of code in your application, no matter how you developed it as long as it works in plain node.js!

Architecture Latest Stable
Windows x86-64 https://enclose.io/nodec/nodec-x64.zip
macOS x86-64 https://enclose.io/nodec/nodec-darwin-x64.gz
Linux x86-64 https://enclose.io/nodec/nodec-linux-x64.gz

For previous releases, cf. https://enclose.io/nodec

Install on Linux

First install the prerequisites:

  • SquashFS Tools 4.3
  • gcc and g++ 4.8.2 or newer, or
  • clang and clang++ 3.4 or newer
  • Python 2.6 or 2.7
  • GNU Make 3.81 or newer

Then,

curl -L https://enclose.io/nodec/nodec-linux-x64.gz | gunzip > nodec
chmod +x nodec
./nodec

Install on macOS

First install the prerequisites:

  • SquashFS Tools 4.3: brew install squashfs
  • Xcode
    • You also need to install the Command Line Tools via Xcode. You can find this under the menu Xcode -> Preferences -> Downloads
    • This step will install gcc and the related toolchain containing make
  • Python 2.6 or 2.7
  • GNU Make 3.81 or newer

Then,

curl -L https://enclose.io/nodec/nodec-darwin-x64.gz | gunzip > nodec
chmod +x nodec
./nodec

Install on Windows

First install the prerequisites:

Then download the executable nodec-x64.exe. Unzip it. Optionally, rename it to nodec.exe and put it under C:\Windows (or any other directory that is part of PATH). Execute nodec from the command line.

Usage

nodec [OPTION]... ENTRANCE
  -r, --root=DIR                   Specifies the path to the root of the application
  -o, --output=FILE                Specifies the path of the output file
  -d, --tmpdir=DIR                 Specifies the directory for temporary files
      --clean-tmpdir               Cleans all temporary files that were generated last time
      --keep-tmpdir                Keeps all temporary files that were generated last time
      --make-args=ARGS             Passes extra arguments to make
      --vcbuild-args=ARGS          Passes extra arguments to vcbuild.bat
  -n, --npm=FILE                   Specifies the path of npm
      --skip-npm-install           Skips the npm install process
      --npm-package=NAME           Downloads and compiles the specified npm package
      --npm-package-version=VER    Downloads and compiles the specified version of the npm package
      --auto-update-url=URL        Enables auto-update and specifies the URL to get the latest version
      --auto-update-base=STRING    Enables auto-update and specifies the base version string
      --debug                      Enable debug mode
  -v, --version                    Prints the version of nodec and exit
  -h, --help                       Prints this help and exit
      --examples                   Prints usage examples

It's all you need to do, you don't have to tweak your project in order to compile with node-compiler!

Learn More

How it works

Comparing with Similar Projects

Project Differences
pkg Pkg hacked fs.* API's dynamically in order to access in-package files, whereas Node.js Compiler leaves them alone and instead works on a deeper level via libsquash. Pkg uses JSON to store in-package files while Node.js Compiler uses the more sophisticated and widely used SquashFS as its data structure.
EncloseJS EncloseJS restricts access to in-package files to only five fs.* API's, whereas Node.js Compiler supports all fs.* API's. EncloseJS is proprietary licensed and charges money when used while Node.js Compiler is MIT-licensed and users are both free to use it and free to modify it.
Nexe Nexe does not support dynamic require because of its use of browserify, whereas Node.js Compiler supports all kinds of require including require.resolve.
asar Asar keeps the code archive and the executable separate while Node.js Compiler links all JavaScript source code together with the Node.js virtual machine and generates a single executable as the final product. Asar uses JSON to store files' information while Node.js Compiler uses SquashFS.
AppImage AppImage supports only Linux with a kernel that supports SquashFS, while Node.js Compiler supports all three platforms of Linux, macOS and Windows, meanwhile without any special feature requirements from the kernel.

Examples

Compile a CLI tool

git clone --depth 1 https://github.com/jashkenas/coffeescript.git
cd coffeescript
nodec bin/coffee
./a.out (or a.exe on Windows)

Compile a web application

git clone --depth 1 https://github.com/eggjs/examples.git
cd examples/helloworld
npm install
nodec node_modules/.bin/egg-bin
./a.out dev (or a.exe dev on Windows)

See Also

  • Libsquash: portable, user-land SquashFS that can be easily linked and embedded within your application.
  • Libautoupdate: cross-platform C library to enable your application to auto-update itself in place.