Reputation: 109
I am creating a project. This project will log payment details when a payment is created.
import * as fs from 'fs/promises';
import * as path from 'path';
app.use('/files', async (req, res) => {
const filePath = path.join(
`log-files/test_${moment().format('YYYY-MM-DD')}.txt`
);
const value = 'TEST FILE CREATION IN AWS';
try {
await fs.readFile(filePath);
await fs.appendFile(filePath, `\n\n${value}`);
res.status(200).send(`File created in, ${filePath}`);
} catch (error) {
await fs.writeFile(filePath, value);
console.log(error);
res.status(200).send(`File created in, ${filePath}`);
}
});
The above is the code I tried.
This is my script to create the file. It works well in local, but when in AWS CodeCommit,
the API calling is success and log with File created in, log-files/test_2024-09-30.txt
But when I check in log-files
folder under the repo, it doesn't have this file.
Upvotes: 0
Views: 49