We now have a youtube channel. Subscribe!

Node.js | Packaging

Node.js | Packaging


Hello folks! welcome back to a new edition of our tutorial on Node.js. In this section of our tutorial on Node.js, we will be studying about Node.js Packaging.

JXcore, an open source project, introduces a distinctive feature to package and encrypt source files and some other assets into JX packages.

Consider you have a big project comprised of many files. JXcore can pack them all into a single file to simplify the distribution. This tutorial gives a quick overview of the whole process starting from JXcore installation.

JXcore Installation

Installing JXcore is quite simple. Here we've provided a step by step instructions on how to install JXcore on your system. Follow the steps given below -

Step One

Download the JXcore package from the link https://github.com/jxcore/jxcore, based on your operating system (OS) and machine architecture. We downloaded a package for Cenots running on 64-bit machine.

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

Step Two

Unpack the downloaded file jx_rh64.zip and copy the jx binary into /user/bin or it may be in any other directory based on your system setup.

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

Step Three

Set your PATH variable appropriately to run jx from anywhere you like.

$ export PATH=$PATH:/usr/bin


Step Four

You can confirm your Installation by simply giving a simple command as shown below. You should find it working and printing the number of its version as follows -

$ jx --version
v0.10.32

Packaging the Code

Let us consider that you have a project with the following directories where you kept all your files which includes Node.js, main file, index.js, and all modules installed locally.

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

To package the above project, you basically need to go inside this directory and give the following jx command. Assuming index.js is the entry file for your Node.js project -

$ jx package index.js index

Here you could have made use of any other package name instead of index. We've used index because we wanted to keep our main file name as index.js. Notwithstanding, the above command will pack everything and is going to create the following two files -

  • index.jxp - An intermediate file which has the complete project detail that is needed to compile the project.
  • index.jx - A binary file having the full package, ready to be shipped to your client or production environment.

Lunching JX File

Consider your original Node.js project was running as follows -

$ node index.js command_line_arguments

After compiling your package using JXcore, it can be started with the following code -

$ jx index.jx command_line_arguments


Alright guys! This is where we are going to be rounding up for this tutorial. In our next tutorial, we are going to be starting a series on Next.js.

Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2022 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain