0

I have an AWS-hosted MySQL database with 900+ records. I've developed a Node script that queries the database for new records, generates MP3 files for each one, uploads those files to S3 storage, and inserts the links into my database.

Right now, I'm having to execute that script manually via command prompt (npm). The script only needs to be run occasionally, so running it manually isn't a problem. But I'm sure there's an easier way than command prompt.

Is there a way to automatically run the script every so often? Or perhaps run it via a desktop shortcut? I'm open to ideas on this...just looking to simplify.

I am very new to Node and all things programming, so please forgive my ignorance here.

Dakota Lynch
  • 169
  • 2
  • 11
  • https://stackoverflow.com/questions/5849402/how-can-you-execute-a-node-js-script-via-a-cron-job Schedule a cron job to run the script at fixed intervals. – tverghis Feb 14 '18 at 17:00

1 Answers1

2

In Linux, you could run as a pure Linux shell script. Use a cron job to schedule the script.

Ex :

#!/usr/bin/env node
console.log('Hello world!');

In Windows, if you want to run manually, you could create a bat file and run the bat file to run the script.

Ex :

name : my_node_script.bat

node c:\path\to\file\my_node_script_code.js

If you want to run the bat file periodically, you could use Task Scheduler to schedule the bat file. See this guide of you want more details on scheduling.

Ishan Thilina Somasiri
  • 1,179
  • 1
  • 12
  • 24