如何每小时在nodeserver中运行一个脚本?

时间:2022-06-01 17:56:16

I have a mean.js project, with this structure in the app (where the server files are):

我有一个mean.js项目,在app中有这个结构(服务器文件所在的位置):

-app
 --controllers
 --models
 --docs
 --logs
 --routes
 --tests
 --views
 bower.json
 Gruntfile.js
 package.json
 README.md

I want to do a "cron job" every hour or so on my mongodb.

我想每小时左右在我的mongodb做一个“cron job”。

I ran into this:

我碰到了这个:

https://github.com/scripting/noderunner

Where should i place it and how do i use it let's say for the sake of example, to do console.log of "hello world" every 1 hour?

我应该把它放在哪里以及我如何使用它让我们说,例如,每1小时做一次“你好世界”的console.log?

1 个解决方案

#1


2  

first you must install cron to your os, after this you must set cron job, for do this you must write "crontab -e" in console and set job, somthing like this:

首先你必须将cron安装到你的操作系统,在此之后你必须设置cron job,为此你必须在控制台中编写“crontab -e”并设置job,如下所示:

0 * * * * /home/user/project/bin/your_script.js

Important! You must add hashbang(#!/usr/bin/env node ) to first line in you script and set permissions. Good luck.

重要!您必须将hashbang(#!/ usr / bin / env节点)添加到脚本的第一行并设置权限。祝你好运。

#1


2  

first you must install cron to your os, after this you must set cron job, for do this you must write "crontab -e" in console and set job, somthing like this:

首先你必须将cron安装到你的操作系统,在此之后你必须设置cron job,为此你必须在控制台中编写“crontab -e”并设置job,如下所示:

0 * * * * /home/user/project/bin/your_script.js

Important! You must add hashbang(#!/usr/bin/env node ) to first line in you script and set permissions. Good luck.

重要!您必须将hashbang(#!/ usr / bin / env节点)添加到脚本的第一行并设置权限。祝你好运。