Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

345
Views
Cleaning temporary files after file upload with restify

I am building a node storage server with restify. I am processing uploads via restify.bodyParser, which under the hood uses formidable.

Formidable stores files in os.tmpDir() by default, and I need to change that to some other folder, and so I did via restify.bodyParser({uploadDir: '/path/to/new/tmp'}).

The problem is that those temporary files are kept in the tmp directory even after I finish processing the request.

I have seen this question (Handling Temporary Files after upload), that supposes to just delete the tmp file after processing it.

My question is, do you need to always manually remove the file? Even with the default os.tmpDir() directory? How does the default system tmp folder work? Does it flush itself sometimes?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Generally, for file uploads, your code moves the uploaded file from its temporary location to a more permanent location. If, after processing the upload, you are left with a temporary file, you are supposed to clean it up manually (using fs.unlink()).

On UNIX-type operating systems, os.tmpDir() (which is usually /tmp) isn't cleaned up periodically by the system (although it is typically cleared during system boot).

over 4 years ago · Santiago Trujillo Report

0

You can delete a single file, or all files

import rimraf from 'rimraf';
import fs from 'fs';

export class DiskCleaner {
  constructor(public folderName: string) {
    Object.setPrototypeOf(this, DiskCleaner.prototype);
  }

  removeDirectory(): void {
    try {
      rimraf(this.folderName, function () {});
    } catch (error) {}
  }
  unlinkFile(path: string): void {
    fs.unlinkSync(path);
  }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!