node-cron-runner
v2024.9.1-8.0
Published
NodeJS CRON runner
Downloads
1
Readme
node-cron-server
Setup
Install and import node-cron-server
.
Have a directory to house your plugins.
- Put secondary modules somewhere else so they don't clutter the auto-run mechanism.
Pass your plugins path as an argument to
NCS.main(...)
. Run you mainjs
script somehow, somewhere...
import NCS from 'node-cron-server'
import path from 'path'
const __dirname = path.resolve()
const pluginDirectory = process.env.PLUGIN_DIRECTORY || 'plugins'
const pluginPath = path.join(__dirname, pluginDirectory)
NCS.init(pluginPath)
NCS.start()
Plugins
This is the expected format for a plugin:
const self = {
name: 'Plugin Name',
description: 'Plugin Description',
// cron time format, see https://www.npmjs.com/package/node-cron
cron: '0 0 0 * * *', // every day at midnight
task: async function() {
console.log(`${self.name} is running`)
}
}
export default self
Every js
file in the plugins
directory is auto-run.