Home >>Nodejs Tutorial >Node.js - Packaging

Node.js - Packaging

Node.js - Packaging

JXcore, an open source project, implements a unique feature into JX packages for packaging and encryption of source files and other properties.

Imagine making a big project consisting of many of files. To simplify the distribution JXcore can load all of them into a single file. This chapter provides a brief overview of the entire process starting with JXcore installation.

JXcore Installation

JXcore is quite easy to run. Step-by-step instructions on how to install JXcore on your system are given here. Follow the steps below to –

Step 1

Download the JXcore package as per your operating system and machine architecture from https:/github.com/jxcore/jxcore. We downloaded a package that runs on 64-bit machine for Cenots.

$ wget https://s3.amazonaws.com/nodejx/jx_rh64.zip
Step 2

Unpack the downloaded file jx rh64.zipand to copy the jx binary to /usr / bin or to some other directory depending on the configuration of your system.

$ unzip jx_rh64.zip
$ cp jx_rh64/jx /usr/bin
Step 3

Set your PATH variable to run jx from wherever you want.

$ export PATH=$PATH:/usr/bin
Step 4

Installation can be verified by issuing a simple command as shown below. You will find it working and its version number printed as follows –

$ jx --version

Packaging the Code

Consider having a directory with the following folders where all of your files, including Node.js, main file, index.js and all locally installed modules, are kept.

drwxr-xr-x  2 root root  4096 Nov 13 12:42 images
-rwxr-xr-x  1 root root 30457 Mar  6 12:19 index.htm
-rwxr-xr-x  1 root root 30452 Mar  1 12:54 index.js
drwxr-xr-x 23 root root  4096 Jan 15 03:48 node_modules
drwxr-xr-x  2 root root  4096 Mar 21 06:10 scripts
drwxr-xr-x  2 root root  4096 Feb 15 11:56 style

You simply need to go within this directory to package the above project and issue the following jx order. Assuming index.js is your project entry file − Node.js

$ jx package index.js index

You might have used some other name for the kit instead of index here. Since we decided to keep our main file name as index.jx we used index. The above command however bundles all and generates the following two files –

Index.jxpIt is an intermediate file that includes all the specifics of the project required to compile it.

Index.jxThis is a binary file that contains the complete package ready for distribution to the client or production environment.

Launching JX File

Consider your initial project Node.js running like this –

$ node index.js command_line_arguments

You can start this after compiling your package using JXcore as follows –

$ jx index.jx command_line_arguments

No Sidebar ads