Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
connect-mongoose-session
Advanced tools
connect-mongoose-session is a mongoDB session store backed by mongoose(http://github.com/LearnBoost/mongoose).
via npm:
$ npm install connect-mongoose-session
## Function
This module covers the session store feature.
session#set
session#get
session#destroy
session#count
session#length
session#clear
Lifetimes can be specified any time
express
supported.
Support the replica set
of MongoDB
lifecheck - Lifetime (ms) [-1 off]
var sys = require('sys')
, http = require('http')
, connect = require('connect')
, MongooseStore = require('connect-mongoose-session');
http.IncomingMessage.prototype.flash = function (type, msg) {
var msgs = this.session.flash = this.session.flash || {};
if (type && msg) {
(msgs[type] = msgs[type] || []).push(msg);
} else if (type) {
var arr = msgs[type];
delete msgs[type];
return arr || [];
} else {
this.session.flash = {};
return msgs;
}
};
connect.createServer(
connect.favicon(),
connect.bodyParser(),
connect.cookieParser(),
connect.session({
key: 'sid',
secret: 'secret-key',
store: new MongooseStore(
['mongodb://localhost:27017/devulopment'], // single or mongos
//['mongodb://localhost:27017/devulopment', 'mongodb://localhost:27018/devulopment'], // replica set
{lifecheck: 30*1000}, // 30 sec
function(err){
return;
}),
cookie: {
path: '/',
httpOnly: true,
maxAge: 60 * 1000 // 1 min
}
}),
function (req, res) {
req.session.count = req.session.count || 0;
req.session.count++;
req.sessionStore.length(function(err, len){
if (req.session.count < 10) {
var info = req.flash('info').join('\n');
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write(info);
res.write('<html><head><title>connect-mongoose - sample</title></head>');
res.write('<body>');
res.write('<form method="post">');
res.write('<input type="hidden" name="foo" value="bar" />');
res.write('<input type="submit" value="POST request!" />');
res.write('</form>');
res.write('<hr />');
res.write('<p>online : ' + len + '</p>');
res.end('<p>count: ' + req.session.count + '</p>');
} else {
req.session.regenerate(function(){
req.flash('info', 'New session. <strong>'
+ req.sessionID
+ '</strong>');
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('regenerated session.');
});
}
});
}
).listen(3000);
sys.puts('Connect server started on port 3000');
TODO
FAQs
mongodb session store for connect and mongoose
We found that connect-mongoose-session demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.