简体   繁体   English

托管在 heroku 上的 MERN 应用程序的架构帮助

[英]Architecture help for MERN app hosted on heroku

I am new to React and to whole MERN concept, by now I created 1 React app and 1 MERN app so now I wanted to take my skill to higher level and challenge myself to creating something complex.我是 React 和整个 MERN 概念的新手,现在我创建了 1 个 React 应用程序和 1 个 MERN 应用程序,所以现在我想将我的技能提升到更高的水平,并挑战自己创造一些复杂的东西。

With stack of MERN and deployed to HEROKU, since this is the only thing I know for now.使用一堆 MERN 并部署到 HEROKU,因为这是我目前唯一知道的。

Now, I had an idea where I would create app where there would be users with main currency coins where they would get 1 coin every day at midnight and they could bid with other players in particulate time for items.现在,我有了一个想法,我将创建一个应用程序,让用户拥有主要货币硬币,他们每天在午夜获得 1 个硬币,并且他们可以在特定时间与其他玩家竞标物品。 And later on they could use that items in some sort of arena.后来他们可以在某种竞技场中使用这些物品。 While I spent few days thinking about it I realized few things:虽然我花了几天的时间思考它,但我意识到一些事情:

I don't know how to trigger logic that will executed every day at midnight and where to place it?我不知道如何触发每天午夜执行的逻辑以及将其放置在哪里? I know that it cant be on React part since every user will then have different items so it must be on express but is it on backend or on heroku?我知道它不能在 React 部分,因为每个用户都会有不同的项目,所以它必须在 express 但它是在后端还是在 heroku 上? Are there any npm packages that I can use for that?有没有我可以使用的 npm 包? I found something about CRON npm packages but I am not sure is that is what I need?我发现了一些关于 CRON npm 包的信息,但我不确定这是否是我需要的? Also I noticed that heroku put your free apps to sleep and I dont know will it wake up app if I use free heroku?另外我注意到heroku让你的免费应用进入睡眠状态,我不知道如果我使用免费的heroku它会唤醒应用吗?

You are looking for something called Cron jobs (Scheduled jobs/tasks), it is not tied to NodeJs, it is a global concept for any backend language in computer science.您正在寻找称为 Cron 作业(计划作业/任务)的东西,它与 NodeJs 无关,它是计算机科学中任何后端语言的全局概念。

In NodeJs there are many libraries which you can use to achieve this, but you should go with OS cron scedulers in linux(google them I am jotting concepts so you can search and learn)在 NodeJs 中,您可以使用许多库来实现这一点,但是您应该使用 linux 中的 OS cron 调度程序(谷歌它们,我正在记录概念,以便您可以搜索和学习)

one of the library to use is https://www.npmjs.com/package/node-cron要使用的库之一是https://www.npmjs.com/package/node-cron

and deploying part, check this for heroku support on cron jobs https://devcenter.heroku.com/articles/scheduler和部署部分,检查这个对 cron 作业的 heroku 支持https://devcenter.heroku.com/articles/scheduler

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

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