Zain Ul Abideen
Zain Ul Abideen

Reputation: 459

How to send a file from Server to Client in Node.js

I am writing a login system in Node.js. I am generating password automatically

app.post("/new/user", (req, res,)=>
{
   var passwd = generateRandomPasswd();
   fs.writeFileSync("credentials.txt", "Username : "+req.body.userName+"\nPassword : "+passwd);
})

How can I send this credential file to the client machine??

Upvotes: 1

Views: 407

Answers (1)

akash
akash

Reputation: 829

app.post("/new/user", (req, res,)=>
{
   var passwd = generateRandomPasswd();
   fs.writeFileSync("credentials.txt", "Username : "+req.body.userName+"\nPassword : "+passwd);

   var readStream = fileSystem.createReadStream('credentials.txt');
   readStream.pipe(res);
})

Upvotes: 1

Related Questions