Get full file path in Node.js
javascript, node.js
Solution
var path = require("path");
var absolutePath = path.resolve("Relative file path");
You dir structure for example:
C:->WebServer->Public->Uploads->MyFile.csv
and your working directory would be Public for example, path.resolve would be like that.
path.resolve("./Uploads/MyFile.csv");
POSIX home/WebServer/Public/Uploads/MyFile.csv WINDOWS C:\WebServer\Public\Uploads\MyFile.csv
this solution is multiplatform and allows your application to work on both windows and posix machines.
Problem
I have an application which uploads csv file into a particular folder, say, "uploads". Now I want to get the full path of that csv file, for example, `D:\MyNodeApp\uploads\Test.csv`. How do I get the file location in Node.js? I used multer to upload file.