Reputation: 315
I have to create a zip file of my whole nodejs server app. I should be able to unzip it and run it, without installing dependencies and apps. It should not be a binary file. The dependencies should be flattened.
How to do this thing ?
Upvotes: 1
Views: 4656
Reputation: 315
Thank you, all of you for your help. I got the solution for my question. I am using npm pack to pack the nodejs app. To pack nodejs app with some dependencies like morgan, express we need to use npm bundle it helps to include the other module required for node js app. With this, we don't need to perform npm install. We just have to install bundle and then include bundleDependencies field including the name of required module in package.json. And then perform then run the command npm pack. It will create a tar file just copy this file in other folder and uncompress it and run the server starting file. The place where you are going to run the nodejs file, there nodejs app should be installed
Upvotes: 1
Reputation: 70183
Generally, a Node.js app has its dependencies installed in the node_modules
directory in the project root.
So, after running npm install
(or npm install --production
), you should be able to zip up the project directory and that should be all you need.
If any of your dependencies in node_modules
are native addons, then you will not be able to install them on a different architecture or OS. If there are native addons, you will also want to make sure your target machine has the same version of node
installed as the machine where you created the zip file. (It's a good idea anyway, if you can, to make sure the node version on the target machine is the same as the source machine.)
One obvious requirement of the target host if you do as I describe above is that node
is already installed there. Not sure if that's OK for your use case or not, but sounds like it probably is?
Upvotes: 1
Reputation: 299
I think you might be looking for this: https://github.com/nexe/nexe
Nexe is a command-line utility that compiles your Node.js application into a single executable file.
Upvotes: 0