const fs = require('fs') const { exec } = require('child_process') function paddedZero(value) { return (`0${value}`).slice(-2) } let today = new Date() today = `${today.getFullYear()}-${paddedZero(today.getMonth()+1)}-${paddedZero(today.getDate())}` if (!fs.existsSync(`${today}.md`)) { fs.appendFile(`${today}.md`, `# Notes for ${today}\n\n- `) } // Works in macOS and with typora as markdown editor. Change regarding your environment or md tool. exec(`open -a typora ${today}.md`) // Windows example // exec(`notepad ${today}.md`)