Oh! I feel dumb now, seems like I need to use something like forever, with its w
flag.
NodeJS Express vhosts and updating app.js
質問
I just set up a NodeJS server and wanted to use the vhost function from Express to allow for easy project setup. I want to be able to create a new directory for a new project without going through the hassle of creating new subdomains etc.
Basically, I want to be able to reach project1 at node.domain.com/project1
and project2 at node.domain.com/project2
.
I'm now running server.js
, which is located in the root (node.domain.com/server.js
) and contains:
var express = require('express');
var app = express();
app
.use(express.vhost('node.domain.com', require('./project1/app.js').app))
.use(express.vhost('node.domain.com', require('./project2/app.js').app))
.listen(3000);
It's all working fine, when I go to node.domain.com/project1
I get the results of ./project1/app.js
but whenever I change something in any of the app.js
files it requires a restart (Ctrl+C
followed by node server.js
) for it to update the changes.
And the contents of app.js are, for example:
var express = require('express');
var app = exports.app = express();
app.get('/project1', function(req, res){
res.send('Hello World [/project1]');
});
Any idea why this is?
A thing to note is that I also run Apache on the same server, and I'm using this guide to allow both servers to run on port 80 (but accesible via different subdomains).
解決