Create a Proxy Server

Sometimes a server will only talk to a server so if you want something from it's API you'll have to create server that will ask for you. We'll build an HTTP server much like we did in the earlier challenge, but we'll use it as a proxy to go between the browser and the other server.

Clone the Repo

We've created a repo with a proxy server. In Bash, navigate to where you want to have the files and clone:

git clone https://github.com/diy/proxy-server.git

Next, go into the repo's folder and open the files:

cd proxy-server
open .

If you're on a PC, to open the folder you'll type start .

Open proxy.js in Sublime (or whatever text editor you use). It should look like this:

proxy server

require()

Notice on line 3 we create a variable called request which is equal to require('request'). This is what you type to use a module from NPM in your code. We're using the module request to help us write this proxy server and we call it specifically in line 11.

Edit Request

On line 8, remove goldenrod and type your DIY username so that it returns your stream data. Save the file.

Install Chrome JSON Viewer

Just like we needed to isntall a Node.js module in Bash to view prettier JSON, we need to install an extension in Chrome to do the same. Install this JSON Viewer extension from Google.

Run the Proxy Server

Back in Bash run the server:

node proxy.js

Now visit localhost:8080 in your browser. BAM! The most recent things from your stream in its raw data form.

stream json