continuous deployment with node/express/mongo app and typescript [closed]

会有一股神秘感。 提交于 2020-01-08 03:32:46

问题


From what I have seen so far, nodejs apps get deployed either by creating a completely static bundle (e.g. angular), or by pulling the source from the repo and running npm install and npm start (usually seen when express/mongo are used).

However, I am developing an express/mongo app paired with typescript, and pulling from the repo would require to build the typescript (again) on the production server, which is ugly and also requires to have typescript and all @types/* packages as production-dependencies. So I was wondering: what are the best practices? Is it a good idea to build & bundle all necessary (.js) files and push them to the server together with package.json, so I can still run npm install? What would be a better way?


回答1:


You are correct that you don't want to be compiling typescript on a production server. Generally, you want to take care of all building and dependency management before you hit production. This means creating a build pipeline that outputs a standalone application for deployment.

A typical build pipeline might look like this:

npm installlintbuildbundle *.js and node_modulesdeploy

A setup like this isolates installing dependencies, linting, and building to the pipeline. Only *.js files, an already installed node_modules directory, and package.json (if it contains the startup script) actually get deployed.

The build pipeline can be done manually, by running a build script and copying the output to the production server. However, a better way is to use one of the many build automation solutions that are available, such as Jenkins, Travis CI, or GitLab CI.



来源:https://stackoverflow.com/questions/57560850/continuous-deployment-with-node-express-mongo-app-and-typescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!