Guest User

Untitled

a guest
Jul 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. http.createServer(function (r) {
  2. if (r.method == 'GET') {
  3. r.writeResponse(200, {'Content-type': 'text/plain'});
  4. r.write('hello world\n');
  5. r.close();
  6. } else if if (r.method == 'POST') {
  7. r.writeResponse(200, {'Content-type': 'text/plain'});
  8. r.close();
  9. } else {
  10. r.startResponse(500, {'Content-type': 'text/plain'});
  11. r.write('error\n');
  12. r.close();
  13. }
  14. });
  15.  
  16.  
  17. // upload
  18. //
  19. http.createServer(function (r) {
  20. var bytes = 0;
  21. r.addListener('data', function (d) {
  22. bytes += d.length;
  23. });
  24. r.addListener('end', function () {
  25. r.writeResponse(200, {'Content-type': 'text/plain'});
  26. r.write('you uploaded ' + bytes + ' bytes\n');
  27. r.close();
  28. });
  29. });
Add Comment
Please, Sign In to add comment