How to create a directory if it doesn t exist using Node js

0 votes

Is this the right way to create a directory if it doesn't exist. It should have full permission for the script and readable by others.

var dir = __dirname + '/upload';
if (!path.existsSync(dir)) {
    fs.mkdirSync(dir, 0744);
}
Jul 20, 2020 in Node-js by kartik
• 37,520 points
841 views

1 answer to this question.

0 votes

Hello @kartik,

Try this:

var fs = require('fs');
var dir = './tmp';

if (!fs.existsSync(dir)){
    fs.mkdirSync(dir);
}

Hope it helps!!
Thank you!!

answered Jul 20, 2020 by Niroj
• 82,840 points

Related Questions In Node-js

0 votes
1 answer

How to update a value in a json file and save it through node.js?

Hello @kartik, It's particularly useful if you're concerned ...READ MORE

answered Oct 12, 2020 in Node-js by Niroj
• 82,840 points
25,942 views
0 votes
1 answer

How to download a file with Node.js without using third-party libraries?

Hii, You can create an HTTP GET request and pipe ...READ MORE

answered Nov 24, 2020 in Node-js by Niroj
• 82,840 points
1,277 views
0 votes
1 answer

How to print a stack trace in Node.js?

Hello @kartik, To print stacktrace of Error in console in ...READ MORE

answered Jul 9, 2020 in Node-js by Niroj
• 82,840 points
870 views
0 votes
1 answer

How to create an HTTPS server in Node.js?

Hello @kartik, The minimal setup for an HTTPS ...READ MORE

answered Jul 13, 2020 in Node-js by Niroj
• 82,840 points
1,877 views
0 votes
1 answer

How to download and install Lavavel framework?

Hey @kartik, First you must have xampp install ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,840 points
1,443 views
0 votes
1 answer

Display Laravel in browser by using cmd promt?

Hello, First you need to have laravel install ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,840 points
1,221 views
0 votes
1 answer

How can we get started with Laravel through Xampp?

Hii, First you need to start Apache and ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,840 points
1,018 views
0 votes
1 answer

How to change Laravel official name to any customize name?

Hey, You just need to go Laravel folder through ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,840 points
3,056 views
0 votes
1 answer

How to create a directory if it doesn't exist using Node.js?

Hello @kartik, Try: var fs = require('fs'); var dir = ...READ MORE

answered Jul 9, 2020 in Node-js by Niroj
• 82,840 points
6,163 views
0 votes
1 answer

How to create a pair private/public keys using Node.js crypto?

Hello @kartik, nodejs v10.12 now supports this natively ...READ MORE

answered Oct 15, 2020 in Node-js by Niroj
• 82,840 points
4,841 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP