Using pm2 I would like to deploy a node app written in typescript.
The repo of this app sitting on git, the remote machine got an ssh connection to git.
What is the standard work flow for deployment in this case ?
on the git repo of course there's only the source (uncompiled) code, and ideally only the compiled (no .ts files) will be sitting on the server.
On what stage the compilation should take place ? and where ?
If some of you encounter this scenario and got an actual example, a concrete configuration for this, it would be very very helpful
Note:
Using heroku, I just add a "postinstall": "npm run build"
script in package.json
and had a Procfile with somting like web: npm start
,
for some reason in this case things are more complicated.
additionally the deployment is to Ec2 linux instance, with standard environment (node, git, pm2 global, and all typescript dependencies if needed, etc.)
Ideally you use a build-server like travis-CI or gitlab-CI that builds, tests and deploys your source.
I asked a similar question recently and ended up building the following pipeline:
npm install
to install node_modules
*dist
foldernpm prune --production
to remove dev-dependencies from node_modules
scp
to copy dist
and node_modules
to prod serverssh
to remove files from earlier deployments and to tell pm2 to reload server.js
* note that if you use modules that use native code and thus are compiled on npm_install
(node-gyp), you have to make sure your build-server uses the same architecture as your production environment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With