theCJarmy7

Node thing

Jun 14th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const fs = require("fs")
  3.  
  4. const app = express();
  5.  
  6. var bodyParser = require("body-parser")
  7.  
  8. app.use(bodyParser.urlencoded({extended:false}));
  9. app.use(bodyParser.json())
  10.  
  11. app.get('/', (req, res) => {
  12.   res.send(fs.readFileSync("test.txt",{"encoding":"utf-8"}))
  13. });
  14.  
  15. app.post("/", function(req, res){
  16.     fs.appendFile("test.txt",req.body)
  17.  
  18.     res.writeHead(200, {'Content-Type': 'text'});
  19.     res.end('thanks');
  20. })
  21.  
  22. app.listen(3000, () => {
  23.   console.log('server started');
  24. });
Advertisement
Add Comment
Please, Sign In to add comment