Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

create and get all the files in a directory with nodejs

const fs = require("fs");

// create a new directory 'assets' in the root directory
const folderPath = "./assets";

fs.mkdirSync(folderPath);

// create a file named 'shakespear.txt'
let fileContent = "Now is the winter of our discontent
Made glorious summer by this sun of York;
And all the clouds that lour'd upon our house
In the deep bosom of the ocean buried";

let filePath = folderPath + '/shakespear.txt';
fs.writeFileSync(filepath, fileContent);

// Read and returns the name of all files in the directory
try{
  files = fs.readdirSync(folderPath);
}catch(error){
  console.log(error);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript url 
Javascript :: Get google maps getplace lat and long 
Javascript :: how to get keys in an object javascript 
Javascript :: scroll down angular with animation 
Javascript :: angular 11 support versions nodejs 
Javascript :: javascript for loop 
Javascript :: chart-js-2 
Javascript :: jade cdn 
Javascript :: readmore jquery plugin 
Javascript :: angular async 
Javascript :: javascript split text after x characters 
Javascript :: Add Text Inside Of React Component 
Javascript :: to array javascript 
Javascript :: get value from input by id in angular 
Javascript :: bitcoin prices in javascript 
Javascript :: js class 
Javascript :: before unload 
Javascript :: react select dropdown 
Javascript :: promise syntax in js 
Javascript :: js detect mouse support 
Javascript :: create a component in react 
Javascript :: puppeteer set up code 
Javascript :: live server in javascript 
Javascript :: if and else shorthand 
Javascript :: access an object js 
Javascript :: cheapest node js hosting 
Javascript :: basic json syntax 
Javascript :: Enqueuing JavaScript in WordPress 
Javascript :: Origin http://localhost:3002 is not allowed by Access-Control-Allow-Origin. 
Javascript :: if without else javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =