How to use the rename function from fs-promise

Find comprehensive JavaScript fs-promise.rename code examples handpicked from public code repositorys.

138
139
140
141
142
143
144
145
146
147
// Rename the file from it's random name to the file's name plus the uuid
const nameArray = name.split('.');
const fileName = nameArray[0];
const fileExt = nameArray[1];
const filenameWithUuid = `${this.uploadDir}/${fileName}_${uuid}.${fileExt}`;
await fs.rename(file.path, filenameWithUuid);
this.fileList[uuid] = fileObject;
this.app.io.broadcast('fileEvent', {
  uuid,
  event: 'new',
fork icon20
star icon26
watch icon0

175
176
177
178
179
180
181
182
183
184
}).then(function () {
  return extract(archivePath)(archiveDir);
}).then(function () {
  return search(new RegExp(fileName + "$"))(archiveDir);
}).then(function (fp) {
  return fsp.rename(fp[0], filePath);
}).then(function () {
  return fsp.unlink(archivePath);
}).then(function () {
  return fileHash ? checksum(fileHash)(filePath) : null;
fork icon7
star icon12
watch icon0

307
308
309
310
311
312
313
314
315
316
const ext = path.extname(files.image.name);
const newID = sha256(randomstring.generate(10));
let fileID = newID + ext;
const coverImagePath = path.join(`${__dirname}/../../../usersContent/${fileID}`);
const gcsCoverImage = gcs.bucket('hs-cover-image');
fsp.rename(files.image.path, coverImagePath).then(() => {
    // Resize the image first
    return easyimage.resize({
        src: coverImagePath,
        dst: coverImagePath,
fork icon0
star icon1
watch icon2

+ 665 other calls in file

173
174
175
176
177
178
179
180
181
182
if(coverImage && coverImage.size > 1){
    const gcsCoverImage = gcs.bucket('hs-cover-image');
    const newImageId = sha256(randomstring.generate(20) + Date.now());
    const extImage = path.extname(coverImage.name);
    const newFilePath = path.join(`${indexJs.tmp}/${newImageId}${extImage}`);
    fsp.rename(coverImage.path, newFilePath)
    .then(() => {
        sharp(newFilePath)
        .resize(500, 500)
        .toFile(newFilePath)
fork icon0
star icon1
watch icon2

+ 1331 other calls in file