The simplest solution will be:
const path = require("path"); const imageUrl = path.relative(__dirname, req.file.path);
With the help of pathh.relative pre-built function you will be able to extract the relative path easily.