Created
July 9, 2021 09:33
-
-
Save adibenc/6fb09028c57231b7a88165d73a613b37 to your computer and use it in GitHub Desktop.
node js dummy
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
const express = require('express') | |
const constants = require('../app/constants') | |
var dummy = express.Router() | |
const fs = require('fs') | |
function tofile(content, fname){ | |
return fs.writeFile(fname, content, err => { | |
if (err) { | |
console.error(err) | |
return | |
} | |
//file written successfully | |
}) | |
} | |
dummy.get("/:type", function(req, res, next){ | |
const typ = req.params.type; | |
switch(typ){ | |
case "t1": | |
const content = 'Test2' | |
tofile("content", 'dummy/test.txt') | |
res.send(content) | |
break; | |
case "req2file": | |
const datax = req.query | |
console.log(datax) | |
tofile(JSON.stringify(datax) , 'dummy/req2file.txt') | |
// console.log(JSON.stringify(datax) ) | |
res.send(datax) | |
break; | |
default: | |
res.send("No type!") | |
} | |
}) | |
module.exports = dummy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment