SHARE
TWEET

Untitled

a guest Dec 14th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top