简体   繁体   English

在 heroku 中部署 node.js / express / mongoDB ( with typescript )

[英]Deploy node.js / express / mongoDB ( with typescript ) in heroku

Before, in the backend i would not use typescript, i would just use pure javascript, but know, this is my first backend app with typescript.以前,在后端我不会使用打字稿,我只会使用纯 javascript,但要知道,这是我第一个使用打字稿的后端应用程序。

I want to deploy of course this app to heroku, but, i wonder if in the procfile component i have to tell heroku to get the server running in the server.ts, or in the server.js in the dist folder.我当然想将此应用程序部署到heroku,但是,我想知道是否在procfile组件中我必须告诉heroku让服务器在server.ts或dist文件夹中的server.js中运行。

What i'm trying to say, is that, should i compile my code to translate it into pure javascript in the dist folder in order to deplot, or is it okay just to just run the server in the server.ts file ?我想说的是,我应该编译我的代码以将其转换为 dist 文件夹中的纯 javascript 以便 deplot,还是仅在 server.ts 文件中运行服务器就可以了?

This is how my project looks like这就是我的项目的样子

在此处输入图片说明

TypeScript is ultimately just there to help you structure your code properly, as it is meant to be compiled to JavaScript. TypeScript 最终只是帮助您正确构建代码,因为它旨在编译为 JavaScript。 While you can run your server via ts-node on a VM, it is simpler to just compile it to JS and run it on your VM, as at that point it is no different from a typical NodeJS application.虽然您可以通过ts-node在虚拟机上运行您的服务器,但将其编译为 JS 并在您的虚拟机上运行它更简单,因为此时它与典型的 NodeJS 应用程序没有什么不同。 Other advantages are smaller build files since your js files will take up less space and startup time.其他优点是较小的构建文件,因为您的 js 文件将占用更少的空间和启动时间。

That being said there is no stopping you from using ts-node on heroku by putting ts-node index.ts inside your package.json start script, (also ts-node should be in dependencies not devDependencies ), but personally I'd go down the compilation route as that is pretty much just another NodeJS application.话虽如此,通过将ts-node index.ts放在package.json start脚本中,并没有阻止您在 heroku 上使用 ts-node,(同样 ts-node 应该在dependencies devDependenciesdependencies不是devDependencies ),但我个人会去沿着编译路线走下去,因为这几乎只是另一个 NodeJS 应用程序。

See Heroku can't find ts-nodeHeroku 找不到 ts-node

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM