Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js Synchronous version of http.get

I want to write a tester that will test a http server I wrote for class. and I need a synchronous version of http.get/http.post

I wanted to make an object with a "test" method that will return true or false if the test passed but found no way to get the code to wait until the server responds to the get request.

Any suggestions on how this can be done?

like image 209
Bg1987 Avatar asked Nov 03 '22 07:11

Bg1987


1 Answers

You can't do this with Node.js without horrible, busy-waiting hacks. Make your test method asynchronous as well, calling a callback parameter to deliver the results of the test back to the caller. Or use a different language for your unit testing.

like image 166
JohnnyHK Avatar answered Nov 11 '22 05:11

JohnnyHK