Search code examples
node.jscronmeanjs

How to run a script in nodeserver every hour?


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

-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.

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?


Solution

  • 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:

    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.