Software Engineering

Find out how to Obtain a File in NodeJS with none Third Get together Libraries

Find out how to Obtain a File in NodeJS with none Third Get together Libraries
Written by admin


If you want to obtain a file in NodeJS with out utilizing any third occasion libraries, then you are able to do the next.

The NodeJS ecosystem comes with a fs module, that is to indicate the FileSystem in-built library.

First declare your imports:

const http = require('https');
const fs = require('fs');

Now you should use the https module to obtain a file, and write it to a stream utilizing fs.

const https = require("https");
const fs = require("fs");
 
const endpoint = "https://instance/information/some_csv_file";
 
https.get(endpoint, (res) => {
  const file_name = "the_csv.csv";
  const writeStream = fs.createWriteStream(file_name);
});

About the author

admin

Leave a Comment