create file if not exists nodejs

const fs = require('fs');

const filePath = 'myfile.txt';

if (!fs.existsSync(filePath)) { fs.writeFileSync(filePath, 'This is a new file created by Node.js'); }