I\'ve been tinkering with Node.js and found a little problem. I\'ve got a script which resides in a directory called data
. I want the script to write some data to
first taking the full path including directory and extracting the directory
//Just for the sake of example
cwd=process.cwd()
filendir=path.resolve(cwd,'_site/assets/text','node.txt')
// Extracting directory name
mkdir=path.dirname(filendir)
Now make the directory, add option recursive:true as stated by @David Weldon
fs.mkdirSync(mkdir,{recursive:true})
Then make the file
data='Some random text'
fs.writeFileSync(filendir,data)