Answer the question
In order to leave comments, you need to log in
Why can't I set up a session.?
var express=require('express'),
session = require('express-session');
var options = {
host: '127.0.0.1',
port: 3000,
user: 'nodejs',
password: 'c5c58f',
database: 'nodejs'
}
var SessionStore = require('express-mysql-session');
var app=express();
app.use(session({
key: 'session_cookie_name',
secret: 'session_cookie_secret',
store: new SessionStore(options)
}))
app.use(function(req,res,next){
console.log(req.session);
});
http.createServer(app).listen(8080,function(){
console.log('server run');
});
app.use(function(err,req,res,next){ // error
if(app.get('env')=='development'){
console.log();
res.end('Error');
}else{
res.status(err.status||500);
res.render('error');
}
})
{ Error: connect ECONNREFUSED 127.0.0.1:3000
at Object.exports._errnoException (util.js:1016:11)
at exports._exceptionWithHostPort (util.js:1039:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1138:14)
--------------------
at Protocol._enqueue (D:\server\apache\node_modules\mysql\lib\protocol\Proto
col.js:141:48)
at Protocol.handshake (D:\server\apache\node_modules\mysql\lib\protocol\Prot
ocol.js:52:41)
at PoolConnection.connect (D:\server\apache\node_modules\mysql\lib\Connectio
n.js:130:18)
at Pool.getConnection (D:\server\apache\node_modules\mysql\lib\Pool.js:48:16
)
at Pool.query (D:\server\apache\node_modules\mysql\lib\Pool.js:202:8)
at MySQLStore.get (D:\server\apache\node_modules\express-mysql-session\lib\i
ndex.js:130:19)
at session (D:\server\apache\node_modules\express-session\index.js:460:11)
at Layer.handle [as handle_request] (D:\server\apache\node_modules\express\l
ib\router\layer.js:95:5)
at trim_prefix (D:\server\apache\node_modules\express\lib\router\index.js:31
7:13)
at D:\server\apache\node_modules\express\lib\router\index.js:284:7
at Function.process_params (D:\server\apache\node_modules\express\lib\router
\index.js:335:12)
at next (D:\server\apache\node_modules\express\lib\router\index.js:275:10)
at cookieParser (D:\server\apache\node_modules\cookie-parser\index.js:70:5)
at Layer.handle [as handle_request] (D:\server\apache\node_modules\express\l
ib\router\layer.js:95:5)
at trim_prefix (D:\server\apache\node_modules\express\lib\router\index.js:31
7:13)
at D:\server\apache\node_modules\express\lib\router\index.js:284:7
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3000,
fatal: true }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question