Skip to content

Instantly share code, notes, and snippets.

@timhudson
Last active January 17, 2019 11:34
Show Gist options
  • Save timhudson/5288685 to your computer and use it in GitHub Desktop.
Save timhudson/5288685 to your computer and use it in GitHub Desktop.
Internal routing within a single node process using express
var request = require('request')
, express = require('express')
, app = express()
var port = process.env.PORT || 5000
app.get('/api', function(req, res) {
res.send('I am from the API')
})
app.get('/internal', function(req, res) {
request('http://localhost:'+port+'/api').pipe(res) // Will send 'I am from the API'
})
app.listen(port)
@callingmybluff
Copy link

That kind of looks external to me :-p.

Agreed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment