Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace error #1

Open
bipower opened this issue Jul 21, 2014 · 0 comments
Open

replace error #1

bipower opened this issue Jul 21, 2014 · 0 comments

Comments

@bipower
Copy link

bipower commented Jul 21, 2014

I've a js file as following:
var connect = require('connect');
var http = require('http');
var fs=require('fs');

var app = connect();

// gzip/deflate outgoing responses
var compression = require('compression');
app.use(compression());

// store session state in browser cookie
var cookieSession = require('cookie-session');
app.use(cookieSession({
keys: ['secret1', 'secret2']
}))

// parse urlencoded request bodies into req.body
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded());

var logger= require('connect-logger');
app.use(logger('short'));

app.use(function(req,res,next){
console.error('%s %s', req.method, req.url);
next();
});

app.use(function(req, res,next){
if('GET'==req.method && '/'==req.url){
server(res,__dirname+'/index.html', 'text/html');
}
else{
next();
}
});

app.use(function(req, res ,next){

if('GET'==req.method && '/images'==req.url.substr(0,7) && '.jpg'==req.url.substr(-4)){
    server(res,__dirname+req.url, 'application/jpg');
}else{
    next();
}

});

app.use(function(req, res ,next){

res.writeHead(404);
res.end('Not found');

});

//create node.js http server and listen on port
http.createServer(app).listen(3000);

function server(res,path, type){
res.writeHead(200,{'Coent-Type':type});
fs.createReadStream(path).pipe(res);

}

when run node, the error found:
E:\eclipse42_wk\nodeconn\src\node_modules\connect-logger\lib\logger.js:13
format = format.replace(/%date/g, "\x1b[90m" + (moment().format(options.da
^
TypeError: Cannot call method 'replace' of undefined
at parse (E:\eclipse42_wk\nodeconn\src\node_modules\connect-logger\lib\logge
r.js:13:21)
at ServerResponse.res.end (E:\eclipse42_wk\nodeconn\src\node_modules\connect
-logger\lib\logger.js:41:17)
at ReadStream.onend (_stream_readable.js:485:10)
at ReadStream.g (events.js:180:16)
at ReadStream.emit (events.js:117:20)
at _stream_readable.js:929:16
at process._tickCallback (node.js:419:13)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant