I am not asking about deploying Node.js app or how do I deal with node_modules package, I am talking about "upload" my own nodejs code to production server.
So far I have tried 3 ways, each with its own pros & cons
git clone. To reduce to the cloned stuff I use git clone --depth 1 -b release_branch
. But still I got the files I do not need for deployment, e.g except for .git
I also get documents (b/c I put documents in my git repo).
npm install. use npm install git+https://gitusername:gitpassword@myserver/path/to/repo.git
. With proper package.json files
setting I can get my source codes only, which is what I want. But the problem is the directory structure. After running npm install, the directory is like this,
.
├── node_modules
└── package-lock.json
My package is located inside node_modules alongside with its own dependencies.
npm pack. Then upload (scp in my case) the tgz file to server, then npm install tgz_file.tgz --production
But it has the same problem with npm install git+https. It is probably better than npm install git+https
b/c I can control my releases.
So is there other ways (simple) that I can get proper directory structure and source codes only ?
BTW, I know this nodejs express app deploying to production but their discussion is not the same as mine.
----- update -----
Now I am kinda sure npm install tarball
has some bug, so I just tar xf & npm i
I believe this is the simplest solution.