-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (27 loc) · 780 Bytes
/
Copy pathserver.js
File metadata and controls
35 lines (27 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// server.js
const express = require('express');
const app = express();
const path = require('path');
const fs = require('fs').promises;
const renameFiles = async (folderPath) => {
try {
const files = await fs.readdir(folderPath);
for (const file of files) {
const fileInfo = path.parse(file);
const oldPath = path.join(__dirname, folderPath, file);
const newPath = path.join(__dirname, folderPath, `${fileInfo.name}_new${fileInfo.ext}`);
await fs.rename(oldPath, newPath);
}
} catch (error) {
// Handle error here
console.log(error);
}
};
app.get('/', (req, res) => {
renameFiles('./images');
res.send('DONE!')
});
const port = 4000;
app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});