Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Node.js Project to Download CSV Files From URL Using Request Pipe() Stream Method

Posted on January 12, 2023

 

 

Welcome folks today in this blog post we will be downloading csv files from url using request pipe() stream method. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to install the request module using the npm command as shown below

 

 

npm i request

 

 

After that you need to make an index.js file and copy paste the following code

 

 

index.js

 

 

JavaScript
1
2
3
4
5
6
7
const request = require('request')
 
const fs = require('fs')
 
const url = "https://peoplefssdf.sc.fsu.edu/~jburkardt/data/csv/faithful.csv"
 
const file = fs.createWriteStream('output.csv')

 

 

As you can see we are importing the request module at the very top and then we are declaring the csv file url where we will be downloading it and saving it inside the local disk. And then we are declaring the output filename using the createWriteStream() of the fs module.

 

 

JavaScript
1
2
3
4
5
6
7
8
request(url)
.pipe(file)
.on('finish',() => {
    console.log("file is successfully downloaded")
})
.on('error',() => {
    console.log("file url is incorrect")
})

 

 

As you can see we are using the request() module and then passing the url inside it and then we are using the pipe() method to download the csv file stream from the url. And then we are listening on for various events such as finish and error events.

 

 

node index.js

 

 

 

Recent Posts

  • Android Java Project to Merge Multiple PDF Documents From Gallery Using iTextPDF Library
  • Android Java Project to Detect System Hardware & System CPU Info & Display inside TextView Widget
  • Android Java Project to Integrate Google OAuth2 Login & Logout System & Save User Info in SharedPreferences
  • Android Java Project to Export Raw Text to PDF Document Using iTextPDF Library
  • Android Java Project to Export Images From Gallery to PDF Document Using iTextPDF Library
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme