Deploy TypeScript Node.js application in production without docker
Asked Answered
H

1

8

What is the current best practice to deploy TypeScript Node.js applications in production without docker?

In case of using git there is the problem that you need to install all dependencies in order to build the project since the types are required which are usually installed as devDependencies. This also means that you install modules for testing, linting, etc. which are not required at all in production.

I am thinking about adding all types as dependencies which then would allow to run npm install --production in order to avoid installing all devDependencies and still be able to build the project by running npm run build.

Another solution I was thinking about was deployment via npm, similiar to how TypeScript node modules are released and installed but that solution also seems suboptimal.

Hennie answered 18/12, 2019 at 11:14 Comment(0)
D
4

Why would you add all types as dependencies? There is no need for that, your production app shouldn't contain all of your dev dependencies. Usually, when one runs the npm run build command, tsc (typescript compiler) is executed and it transpiles typescript code into javascript. You don't need all of your dev dependencies included in the transpiled code. Default location for transpiled code is usually dist folder. If your application entry point was src/index.ts, then after build command you should call node dist/index.js to run the server. Now, everything you need to package your app for production is your package.json and transpiled code in dist folder. Install prod dependencies and run node dist/index.js and your server should run successfully. Of course, you should consider configuring PM2 or similar process manager for your production code.

Divisibility answered 21/12, 2019 at 23:0 Comment(2)
I agree with everything you said but what tool are you using to package the app (dist folder + package.json) and then deploy it on a server? The goal is to be able to automate the whole process. Of course with docker this is easy but I am trying to find a solution that works without dockerHennie
I’m using AzureDevops. It’s really intuitive and easy to use. It is really easy to pick files and folders you want to package on production serverDivisibility

© 2022 - 2024 — McMap. All rights reserved.