Temporary need a timing screen shot, monitoring the operation of a software, online download software miscellaneous miscellaneous eight, as a direct masturbation, so easy!

  1. Initialize the project

    npm initInitialize a NodeJS project
  2. Prepare the NodeJS class library package
   npm install --save screenshot-desktop  
   npm install --save node-schedule 
   npm install --save moment
Copy the code
  1. A new index. Js
const screenshot = require('screenshot-desktop') const schedule = require('node-schedule') const fs = require('fs') const moment = require('moment') const path = require('path') var rule = new schedule.RecurrenceRule(); rule.minute = 0; // 0 min screenshot console.log(' Waitting screenshot.') var j = schedule.schedulejob (rule,function(){// screenshot screenshot().then( (img) => { var p = path.join(__dirname,moment().format('YYYYMMDD-HHmmss.jpg')) fs.writeFile(p,img,function(err){ if(err){ throw err } }) console.log('screenshot success to '+ p) } ) })Copy the code
  1. Configure the start command to edit package.json
"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
  },
Copy the code
  1. run

    npm start

So easy!