/home2/dakshskx/test.dakshadesign.com
Edit: /home2/dakshskx/test.dakshadesign.com/routes-version1.js (1972B)
const fs = require('fs');
const requestHandler = (req,res) => {
const url = req.url;
const method = req.method;
if(url==='/'){
res.setHeader('Content-Type','text/html');
res.write('');
res.write('');
res.write('
Enter Message');
res.write('');
res.write('');
res.write('
');
res.write('');
res.write('');
return res.end();
}
if(url==='/message' && method==='POST'){
const body = [];
req.on('data', (chunk) => {
console.log('Hii');
console.log(chunk);
body.push(chunk);
});
return req.on('end',() =>{
const parsedBody = Buffer.concat(body).toString();
console.log(parsedBody);
const message = parsedBody.split('=')[1];
console.log(message);
fs.writeFile('demo.txt',message, (err) => {
res.statusCode ='302';
res.setHeader('Location','/');
return res.end();
});
});
}
res.setHeader('Content-Type','text/html');
res.write('');
res.write('');
res.write('
My first Page');
res.write('');
res.write('');
res.write('
Hello This is h1 tagss
');
res.write('');
res.write('');
res.end();
}
module.exports = requestHandler;
/*module.exports = {
handler : requestHandler,
someText: 'Hi this is dummy text'
};*/
/*module.exports.handler = requestHandler;
module.exports.someText ='Hi this is dummy text';*/
/*exports.handler = requestHandler;
exports.someText ='Hi this is dummy text';*/