Closed snsparrish closed 12 years ago
Yes
$ mkdir /tmp/woot
$ cd /tmp/woot
$ npm install express up
$ cat > server.js
(paste)
var app = require('express').createServer();
app.get('/', function (req, res) { res.send('<marquee><h1>hello snsparrish</h1></marquee>'); });
module.exports = app;
(press ctrl+c)
up server.js
Module supplied "_the_file_here.js" does not export a valid http.Server
.
fix ?
?
same problems happening for me.. anytime I use the programatic interface and not the cli.
0.6.10 and newest npm...
I'll post a log shortly
@malkomalko I'm interested in using up from within an express app as well. Haven't written any code yet, but will let you know if I have any success. I know you haven't gotten it working yet, but any gotchas early on I should know about?
Thanks
Did you guys try the example I posted in the comment above?
It looks like the example above requires you to use the up
command to start your program. I'm interested in simulating this example:
var up = require('up')
, master = http.Server().listen(3000)
// initialize up
var srv = up(master, __dirname + '/server');
process.on('SIGUSR2', function () {
srv.reload();
});
Oh. The CLI program uses that API internally so it obviously has to work for that example to work.
In your case, maybe your file is not called /server
so you have to tweak that.
I'll check it out, thanks.
For Express 3.0x
var express = require('express');
var app = express();
var server = app.listen();
app.get('/', function (req, res) { res.send('<marquee><h1>hello snsparrish</h1></marquee>'); });
module.exports = server;
If anyone comes across the error in the OP:
http.js:562
throw new Error("Can't render headers after they are sent to the client.")
It's possibly because you're trying to use your app's http server as the master server. You should create another server for master as all it does is handle proxying to the worker processes.
In my express project I created two files: server.js
and up.js
. server.js
starts (and exports) my express server like above. up.js
starts the up master server.
var up = require('up'),
http = require('http');
var options = {
numWorkers: 2,
workerTimeout: '500ms',
assumeReady: true
};
var master = http.Server().listen(4000);
var srv = up(master, __dirname + '/server', options);
process.on('SIGUSR2', function () {
srv.reload();
});
Will 'up' work with 'express'? I keep getting an error whenever a request is made: http.js:562 throw new Error("Can't render headers after they are sent to the client.")
Thanks, Shawn