0
votes

I have a situation where I have tow express js apps App1 and App2 running on port 80 and 8080 respectively. I have declared these apps in same js file.....now I wanted to share some data from App2 request to App1. Is it possible if yes how I can do that? or can we forward App2 request to App1 directly.

1

1 Answers

0
votes

You can easily do this with vhost() in Express. All you have to do is

var express = require('express'); 
var app = express(); 

app 
.use(express.vhost('localhost', require('/path/to/website1/app.js').app)) 
.use(express.vhost('localhost2', require('/path/to/website2/app.js').app)) 
.listen(3000); 

This will listen on port 3000, and check for specific host names - in this case, localhost and localhost2. If one of those hosts match, it will get an instance of their 'app' to run/use.

In this case you will have to export your app object from app.js to use all the methods and API's you have, You can simply do this by

var express = require('express'); 
var app = exports.app = express();