simple online nosql database database with REST API and MongoDB queries
  • Features
  • Docs
  • Blog
  • Templates
  • Pricing
  • Contact
  • Sign Up
  • Log In

Blog

 The latest news and articles about restdb.io  

Database templates!
Don't forget to visit our template catalog! It's the fastest way to get up and running with a restdb.io database. View templates »

Serverless "cron" jobs with JavaScript Codehooks

by Jon Erik Solheim
|
Tutorials|API|
  • Share on Facebook
  • Tweet
  • Add to Pocket
  • Share on LinkedIn
  • Send email

Crontab is a well known workhorse from the Unix and Linux world. 

The crontab is a system that lets you run commands on a regular schedule. Crontab stands for “cron table”, because it uses the job scheduler cron to execute tasks; cron itself is named after “chronos,” the Greek word for time.

Using the Crontab system, restdb.io can invoke a Codehook. A Codehook is a JavaScript function that can access your database or any other network resource.

Combining Crontab and Codehooks puts you in control. It lets you build a more versatile and advanced data backend for your application.

This blog post shows how to get started creating your own Crontab jobs in restdb.io.

Crontab expressions

A Crontab expression is a special string with five components that builds an expression for a job schedule: 
For example :

  • run job each 10. th minute: */10 * * * *
  • run job at 23:00 each Monday: 0 23 * * 1

Tip: let https://crontab.guru help you build your expression.

Set up a crontab job

In development mode, navigate to the System_jobs collection in the left menu.
Each record in the System_jobs collection is a separate job. These are used to schedule tasks that invokes your Codehook on the Crontab expression.

Start by adding a new record and enter a description, a Crontab expression and finally the Codehook JavaScript. Check the active checkbox to indicate the this job is running, or uncheck to pause job.

background codehooks

Example Codehook that prints 5 items from a collection to the console:

var runJob = function(req, res) {
    db.get("/rest/product", {},{$max: 5}, function(err, data) {
        data.map(function(item){
            log.debug(item);
        });
        res.end();   
    });
}

Using the REST inspector, we can view the output of a Codehook in realtime.


But what if you don't want to be glued to the REST inspector at all times?

That's where the job logs comes in handy.

Logging

You can check the status of any current job in the System_log collection. It shows the res.end(…) output from a job. Any log.debug() statements can be viewed with the REST inspector.

system log


Conclusion

Background Codehooks in restdb.io are simple to set up and alleviates the need for a separate server. Creating serverless applications with powerful integrations, custom logic and long running processes is now a reality.

Read more about Codehooks in the docs.

  • Share on Facebook
  • Tweet
  • Add to Pocket
  • Share on LinkedIn
  • Send email

All Posts


Search

Topics

  • API
  • Authentication
  • Case study
  • Features
  • Howto
  • Integrations
  • Newsletter
  • Productivity
  • Prototyping
  • Tutorials
  • User

restdb.io is a fast and simple NoSQL cloud database service. With restdb.io you get schema, relations, REST API and an efficient multi-user admin UI for working with data.

Our customers use it for backends, business databases, API-first CMS, data collection and much more. It is easy to get started with the free development plan.

Start Building »

  • Site Links
  • Home Page
  • About Us
  • Contact
  • Blog
  • Templates Catalog
  • Cloud Service
  • Features
  • Pricing
  • Terms & Conditions
  • Privacy Policy
  • Sign Up »
  • Documentation
  • Overview
  • Getting Started
  • Coding against the API
  • Utils
  • Security and Admin
© 2025 restdb.io