I find I don’t like to write a lot of words…
The script
index.js
const cron = require('node-cron')
const juejin = require('./juejin.js');
// Timer (1 am every day, can be modified according to your needs)
cron.schedule('0 1 * * *'.() = > {
juejin.checkIn();
})
Copy the code
juejin.js
const axios = require('axios');
const dayjs = require('dayjs');
const fs = require('fs');
const configPath = './config.json';
// Get the configuration
const getConfig = () = > {
return JSON.parse(fs.readFileSync(configPath));
}
/ / sign in
const checkIn = async() = > {const {cookie, baseUrl, apiUrl} = getConfig();
let {data} = await axios({url: baseUrl + apiUrl.checkIn, method: 'post'.headers: {Cookie: cookie}})
console.log(dayjs().format('YYYY-MM-DD HH:mm:ss'), data);
}
module.exports = {
checkIn
}
Copy the code
config.json
{
"baseUrl": "https://api.juejin.cn"."apiUrl": {
"checkIn": "/growth_api/v1/check_in"
},
"cookie": ""
}
Copy the code
use
1. Modify cookies in config.js
How do I get cookies from the browser
2. Install pM2
npm install -g pm2
Copy the code
3. Start the project with PM2
pm2 start index.js --name ***
Copy the code
Git address
Github.com/zhuyuqian/n…