I can't upload files from html form on my node/express app

Posted July 4, 2017 6.3k views
Node.jsUbuntu 16.04


I’m just running a simple Node.js/Express application on a droplet and I can’t upload files to the designated folder from a html form on a page of the application.

I’m just running the application with ‘node app.js’ and it runs on port 3000. I could be wrong but I don’t think Apache is involved here, is that correct?

I’ve chmod 777’d the folder to where the files go but every time I try and upload a file the application hangs for a few seconds and then gets “Killed”.

The upload location is 'app_root/public/uploads’

I am aware of the security issues here, I just want to do a little bit of live testing, I don’t plan to the have the application up for long.

Thanks for any help!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
4 answers

Ok, It’s actually Jimp that is cause the problem here. I was trying to resize the file before saving, and it’s failing somewhere here:

function savePhoto(photo, userId) {
    var timestamp = Math.round((new Date()).getTime() / 1000);
    var photoname = userId + - + timestamp + '.png';, function (err, photo) {
        if (err) throw err;
        photo.resize(400, jimp.AUTO)            
            .write("public/uploads/" + photoname);
    return photoname;

whereas if i use ‘express-fileupload’ to save the file, it works fine:

function savePhoto(photo, userId) {
    var timestamp = Math.round((new Date()).getTime() / 1000);
    var photoname = userId + - + timestamp + '.png';'public/uploads/' + photoname, function(err) {
        if (err) throw err;
    return photoname;

Thanks for any help!

have you included this line your express app setup?


Actually you may need to set up a reverse proxy like nginx which directs all the requests to your node app.

Check this link out.

by Brennen Bearnes
Node.js is an open source JavaScript runtime environment for easily building server-side and networking applications. Node.js applications can be run at the command line but this guide focuses on running them as a service using PM2, so that they will automatically restart on reboot or failure, and can safely be used in a production environment.
  • Is this in case the form request is not hitting the correct end point? Because I have a registration and login form that are finding their end points and working correctly. Would it be different with a file form?

    • what are you using for uploading the file? multer?
      try logging out the output to see if the endpoint is getting a request.

      • for the file uploading im using ‘express-fileupload’, which seems to work fine as i am getting the request to the endpoint, with the file contents, but then i try to resize the file and save it to the file system, this is where it stops and get killed.

        in this link you can see the last log that i am seeing before it dies:

        which is called from the endpoint function here:

        I am using Jimp to do the resize and save. As a test i am going to use the standard express-fileupload method for saving the file, just to see if its not just a problem with Jimps resizing function (which works fine locally).

      • wouldn’t you know it! it seems that Jimp is the problem here for some reason. When I use express-fileupload to actually save the file to the file system it saves fine. But when Jimp tries it, it dies, don’t know if its the resizing part or the file saving part. Oh well, will have to dig into that. Thanks for the help.

i dont know about your issue but i can tell if if specify the full path in the like root/app/public_uploads
then you can easy the access , and this is give multer or other module to access the directory .which is possible from the local host