Upload files to Node.js without form and without third-party frameworks

Salvador Guerrero
2 min readApr 5, 2020

--

Before jumping into Express or any other Node.js frameworks I want to learn a little low-level stuff so that I know what’s happening behind the scenes, so I decided to create a very simple app that shows an html with a button to select an image and then it uploads it to the node.js server as soon as its selected.

I decided not to use html forms also known as application/x-www-form-urlencoded to make it even simpler, I didn’t find any samples out there that did this, I bet there’s something out there but my search keywords didn’t find anything so this is why I’m writing this story to help others that are trying to do the same thing.

I also decided not to use third-party frameworks well because I want to learn more about Node.js, for this sample app I use only the http and fs modules which comes pre-loaded in node.js.

Without further ado, please check the index.js code below that runs in Node.js, and then just below it I show index.html which is loaded in the browsers when opening the website.

I think that the code speaks for itself, if you have any questions please add a comment here or in directly in the GitHub Gist.

One thing that you can do to enhance this app, is to save the files in a cheap storage server instead of saving it to your efficient Node.js server, I’ll be enhancing this sample for my own research to store files in a ftp server located in a private network.

Write you later ✌️

--

--

Salvador Guerrero

Computer Science Engineer, Cross-Platform App Developer, Open Source contributor. 🇲🇽🇺🇸