In my nodeJS application (meteorJS) I need to use an absolut path for creating a file via fs.createWriteStream
:
const absolutePath = '/Users/Anybody/Documents/Project/imports/temp'
if (Meteor.isServer) {
const result = new Promise(function (resolve, reject) {
const gfs = Grid(
MongoInternals.defaultRemoteCollectionDriver().mongo.db,
MongoInternals.NpmModule
)
const readerStream = gfs.createReadStream({ _id: id })
const writerStream = fs.createWriteStream(absolutePath + 'temp.mp4')
// ...
})
}
This is how the code looks like for development, which I do on macOS. The production version of the application is deployed to an ubuntu server. So the absolute path is different.
I tried to use path
:
const path = require('path')
const absolutePath = path.resolve('/imports/temp')
But this gives me only /imports/temp
(on macOS)