DEV Community

Omar Dulaimi
Omar Dulaimi

Posted on

Change file/directory permissions in Nodejs

π—‘π—Όπ—±π—²π—·π˜€ let's you set permissions on files/directories just like you do on your Unix systems.

I'm sure a lot of you have come across the 𝗰𝗡𝗺𝗼𝗱 utility in your OS of choice. Probably also executed something like this:

𝗰𝗡𝗺𝗼𝗱 𝟳𝟳𝟳

Which gives full access to everyone(can be evil). The number you see defines the read, write and execute access to owner, group and others(public).

Same thing can be achieved using the π—³π˜€π—£π—Ώπ—Όπ—Ίπ—Άπ˜€π—²π˜€.𝗰𝗡𝗺𝗼𝗱 method.

π—‘π—Όπ—±π—²π—·π˜€ also provides another version of this method made just for symbolic links; which are aliases to files.

Websites like https://lnkd.in/d7tCvnAw can help you calculate the permission number you need.

Hope this post inspires others to talk about 𝗰𝗡𝗺𝗼𝗱 in more depth at the OS level.


Did you learn something new today?

Like and share this post, and follow me for more!

chmod in node

Top comments (0)