Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Access domain and protocol in Node Cron Job

I have a cron job that is supposed to send an email with a link to the system every month.

However, this is a whiteboxed application that will be run on different domains.

I am trying to dynamically generate the link in the cron job. I have done this before by accessing the req object in a GET or POST request but I know there is no way to access these objects in a cron job. I am trying to find a way to generate the link in the Cron Job with out hardcoding the protocol and domain in the link that is sent out.

See example below:

const express = require("express");
const cron = require('node-cron');
const app = express();

cron.schedule("0 8 1 * *", async () => 
{
    let protocol = `https`; // Functionality to detect if protocol is http or https
    let domainAndPort = `www.test.com:7443`; // Functionality to detect doamin and port that app is listening on.

    let link = `${protocol}://${domainAndPort}/`; 

    //Send Email with Link using nodemailer  


/*
    In a GET or POST request I normally generate the link like this

    let link = `${req.protocol}://${req.headers.host}/`;
*/  
}

app.get("/", function(req, res) 
{
   res.send("HELLO");
});

app.listen(7443, function()
{
    console.log(`Listening on port 7443`);
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!