Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

347
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda