Skip to content

Instantly share code, notes, and snippets.

@adibenc
Created July 9, 2021 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adibenc/6fb09028c57231b7a88165d73a613b37 to your computer and use it in GitHub Desktop.
Save adibenc/6fb09028c57231b7a88165d73a613b37 to your computer and use it in GitHub Desktop.
node js dummy
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