-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
2,495 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
import { readFirstLineFromFile } from '../../utils/fileUtils'; | ||
|
||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
export default function handler(req: NextApiRequest, res: NextApiResponse) { | ||
console.log("from read-file") | ||
if (req.method === 'GET') { | ||
console.log("from read-file handler 1st line ") | ||
const filePath = path.join(process.cwd(), '/Wallets/Contributor/contributor.seed'); | ||
// const filePath = '/Wallets/Contributor/contributor.seed'; // Replace this with your file's path | ||
try { | ||
console.log("From read-file.ts -file name is ", filePath) | ||
const firstLine = readFirstLineFromFile(filePath); | ||
console.log("firstLine is = ", firstLine) | ||
res.status(200).json({ firstLine }); | ||
} catch (error) { | ||
res.status(500).json({ error: 'Error reading file from read-file.' }); | ||
} | ||
} else { | ||
res.status(405).json({ error: 'Method not allowed from read-file.' }); | ||
} | ||
} | ||
|
||
|
||
// import fs from 'fs'; | ||
// import path from 'path'; | ||
|
||
// export default function handler(req, res) { | ||
// if (req.method === 'POST') { | ||
// const filePath = path.join(process.cwd(), 'testfile.txt'); | ||
// const dataToWrite = 'This is the data that will be written to the file.\n'; | ||
|
||
// fs.writeFile(filePath, dataToWrite, (error) => { | ||
// if (error) { | ||
// console.error('Error writing to the file:', error); | ||
// res.status(500).json({ error: 'Error writing to the file.' }); | ||
// } else { | ||
// console.log('Data has been written to the file successfully!'); | ||
// res.status(200).json({ message: 'Data written to the file successfully!' }); | ||
// } | ||
// }); | ||
// } else { | ||
// res.status(405).json({ error: 'Method not allowed.' }); | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
export default function handler(req, res) { | ||
console.log("from writeToFile") | ||
if (req.method === 'POST') { | ||
const filePath = path.join(process.cwd(), 'testfile.txt'); | ||
const dataToWrite = 'This is the data that will be written to the file.\n'; | ||
console.log("from write-toFile= ", filePath) | ||
fs.writeFile(filePath, dataToWrite, (error) => { | ||
if (error) { | ||
console.error('Error writing to the file:', error); | ||
res.status(500).json({ error: 'Error writing to the file.' }); | ||
} else { | ||
console.log('From WriteToFile--- Data has been written to the file successfully!'); | ||
res.status(200).json({ message: 'Data written to the file successfully!' }); | ||
} | ||
}); | ||
} else { | ||
res.status(405).json({ error: 'Method not allowed.' }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.