让hexo在后台运行

2022年09月01日1 min read
踩坑

安装pm2

npm  install -g pm2

写一个运行脚本,在博客根目录下面创建一个hexo_run.js

//run
const { exec } = require('child_process')
exec('hexo server',(error, stdout, stderr) => {
        if(error){
                console.log('exec error: ${error}')
                return
        }
        console.log('stdout: ${stdout}');
        console.log('stderr: ${stderr}');
})

运行命令

pm2 start hexo_run.js