Question: I'm making a testbench with Test'em and Mocha (that run on node.js) in order to test a PHP website.

What I want is to request some URL (e.g <http://www.my-website/test.php>) and get the http status code as well as the content returned.

I'm doing it with the node.js **Request** module.

**The problem is:**

> 
> I need to be authenticated to access this page, otherwise I'm
>  redirected to the login page.
> 
> 
> 

So, does it exist a way to log in my application through Node.js and keep the session open to be able to chain tests on any pages I want?

I was thinking on get the PHPSESSID on login request if it is possible. Do you thing it is a good direction ?

Any help would be much appreciated.

Thank you, have a nice day :)

Michaël

Answer: 
If you set `jar: true` in your [options](https://github.com/mikeal/request#requestoptions-callback) or use your own [custom cookie jar](https://github.com/mikeal/request#examples), then `request` will remember cookies set by the server so that you can keep your session between requests.
Instead of using the request module, use headless browsers like [PhantomJS](http://phantomjs.org) and [zombie.js](http://zombie.labnotes.org). You can even emulate user interaction with these.