Simple Node.js proxy server with Express and Request
One of the best surprises a developer can get is when "stuff just works". Far too often, you'll get tangled up just trying to get a project off the ground. You'll spend too much time just trying to figure out which config file goes where, which version of the library you need, ad nauseum. By the time you are ready to go, you've forgotten what you needed to do.
One of the great things about the Node.js ecosystem is how little I find myself having to do just that. I was recently trying to proxy a simple request and I decided to write an express server. Here's what I came up with:
const express = require("express");
const request = require('request');
const app = express();
app.get('/', (req, res) => request({
url: req.query.url,
method: req.query.method
}).pipe(res);
);
app.listen(8080);
Excluding libraries and formatting, you can a proxy up in running in a couple of lines. The code is very readable and handles all different HTTP methods and response types.