Fire and Forget Functions

While deleting FIles in our Node application we sometimes use fire and forget that means we are not checking it back weather our file is deleted or not

To use that

  1. We need to make a file or we can simply use

  2. const fs = require('fs'); const deleteFile = (filePath) => { fs.unlink(filePath, (err) => { if (err) { throw (err); } }) } exports.deleFile = deleteFile;

We are exporting because As a node developer we always need to make our application in a systematic way. So

make a file in the util folder where use this code then

where we have to use this is where we want to delete our image or file which is not usefull now so in our case edit product we have to write

const fileHelper = require('../util/file');

in the post edit page use this


If we want to see the result with that then use the callbacks like this

We are firing this function and We don't care about the result. If we wanted to, we would have to pass my callback here, so a function which then continues with the rest.

fileHelper.deleteFile(product.imageUrl, (err){

throw (err);


0 views0 comments

Recent Posts

See All

SQL UNION Operator UNION operator is used to combine the results of two or more SELECT statements Every SELECT statement within UNION must have the same number of columns The columns must also have si

JOIN clause is used to combine rows from two or more tables. INNER JOIN === selects records that have matching values in both tables SELECT Orders.OrderID, Customers.CustomersID, Orders.OrdersDate FRO