Node.js: is it possible to simulate an HTTP connection without external modules? -
let's assum have basic http server, 1 on nodejs.org:
var http = require('http'); http.createserver(function (req, res) { res.writehead(200, {'content-type': 'text/plain'}); res.end('hello world\n'); }).listen(1337, '127.0.0.1'); console.log('server running @ http://127.0.0.1:1337/');
is possible simulate connection server without using npm module (socket.io, connect etc.) ?
the way have found using pure node.js using http.request , running both instances locally (both server , client simulator). however, unsure drawbacks has or if valid option. work if try simulate multiple connections, example? network speed bottleneck in case? there better/easier way?
sure, can make http request within computer, won't simulating either, you'll making actual connection too. nodejs's built in http module ships client server.
var http = require("http"); http.get("http://localhost:1337", function(resp){ console.log("request made!", resp); });
Comments
Post a Comment