Member-only story

Write a file into specific folder in Node JS example

Bipsmedium
2 min readMay 19, 2023

--

Write a file into specific folder in Node JS example

Hi friends, in this tutorial you will learn how to write a file into specific folder in node js and it is a very basic concept of a node js filesystem. In order to write a file you have to follow the below steps:

Required steps to write a file into specific folder in Node JS

Step 1:- Create a folder inside the node js application or anywhere you want.

Step 2:- Create a file with a .js extension inside the node js application. For eg:- filesystem.js

Also read, Node Js hello world program

Now, before writing a file, you have to include two built-in modules of node js as given below

fs module:- In order to work with the filesystem such as create a file, reading file, update file, and delete a file in node js, there is a built-in module called “fs”. You can use this module with the help of require() method as shown below.

const fs = require("fs");

path module:- In order to get the path of a specific folder of the directory, you can include this module as shown below.

const path = require("path");

Step 3:- In the filesystem.js file, call the above two modules as given below.

--

--

Bipsmedium
Bipsmedium

Written by Bipsmedium

Hi, This is Biplab and I am a PHP laravel developer and other open source technologies. I am here to share my experience with the community.

No responses yet