Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. const http = require('http')
  2.  
  3. const app = new http.Server()
  4.  
  5. app.on('request', (req, res) => {
  6.  
  7. let method = req.method.toLowerCase()
  8.  
  9. if (req.method.toLowerCase() == 'post') {
  10.  
  11. // container to hold the incoming data
  12. var data = ""
  13.  
  14. req.on('data', (chunk) => {
  15. // append as data keeps coming in
  16. data += chunk.toString()
  17. })
  18.  
  19. req.on('end', () => {
  20. // all the data has been received
  21. console.log(data)
  22.  
  23. res.writeHead(200, { 'Content-Type': 'text/plain' })
  24. res.write('got it')
  25. res.end('\n')
  26. })
  27.  
  28. }
  29. })
  30.  
  31. app.listen(10588)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement