How To Use jQuery To Post A CSV File To A Node.js Server

If you have a front-end that needs to accept a CSV file, upload it to a server using jQuery, and then have that Node.js server process that CSV file, then this a way to do it.

First up, the HTML

and then the jQuery that takes the selected CSV file, and uploads it to a server

and finally the Node.js file that will accept and process it using Express (with the multer middleware), and then iterate through the CSV file.

As it turns out, the Node.js CSV libraries I found on npm were either not working or hadn’t been updated in a long time. To process a CSV file with standard JS using functions like split and replace made this relatively easy to do on my own.

Any questions let me know!

2 responses to “How To Use jQuery To Post A CSV File To A Node.js Server”

  1. Hey your article was really helpful though I was a bit confused regarding the ajax url and what should I use there like should it be some thing like localhost:3000/upload or something else ?

    • Hey Sam. If you’re just testing both frontend and backend locally the URL from the above example would be localhost:3000/test

      I use ngrok if I’m testing this out on a remote front end to tunnel to my local dev server.

      Make sense?

Leave a Reply

Your email address will not be published.