I'm trying to generate a folder and a file within that folder. Below is the function i wrote in Node.js. The problem is, I'm able to generate the folder but the file generation does not work.
Could anyone please help?
const createDir = (folderName) => {
fs.mkdirSync(
process.cwd() + '/' + folderName,
{ recursive: true },
(error) => {
if (error) {
console.error('An error occured', error);
} else {
console.log('Your directory is made!');
fs.writeFile(`/${folderName}/${folderName}.js`, '', (error) => {
if (error) {
console.error('An error occured', error);
} else {
console.log('file created!');
}
});
}
}
);
};