I need to run multiple Node apps on the same port. I've found out that I can run multiple node apps using one port, thanks to this SO question Running multiple Node (Express) apps on same port But it's not working for me probably bec. I'm using Restify unless I did something wrong somewhere.
I already have "app1" running on this one port using PM2 built using Restify. I've made another app "app2". The paths are like these:
/var/www/app1
/var/www/app2
with each app having common routes like these:
app.get('/', func...);
app.get('/about', func...);
app.post('/foo', func...);
app.post('/bar', func...);
I've set up "app1"'s last lines of code as: exports.app = app
instead of app.listen(8080, function() { ... });
and, where app
is
var app = restify.createServer({
name: 'app1'
});
"app2" is the same as well...
My main.js
file (which is saved in /var/www/
) is also built on Restify:
main
.use('/app`', require('./app1/index').app)
.listen(8080);
where main
is
var main = restify.createServer({
name: 'main'
});
But I'm getting an error such as this when I type node main.js
(I haven't tried with PM2 yet):
/var/www/node_modules/restify/node_modules/assert-plus/assert.js:45
throw new assert.AssertionError({
^
AssertionError: handler (function) is required
at process (/var/www/node_modules/restify/lib/server.js:76:24)
at argumentsToChain (/var/www/node_modules/restify/lib/server.js:84:13)
at Server.use (/var/www/node_modules/restify/lib/server.js:625:6)
at Object.<anonymous> (/var/www/main.js:47:8)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
Note: I've turned off all the apps running under PM2. There are no node apps running on any port.