Understanding passport serialize deserialize

How would you explain the workflow of Passport’s serialize and deserialize methods to a layman. Where does user.id go after passport.serializeUser has been called? We are calling passport.deserializeUser right after it where does it fit in the workflow? // used to serialize the user for the session passport.serializeUser(function(user, done) { done(null, user.id); // where is … Read more

Express.js req.body undefined

I have this as configuration of my Express server app.use(app.router); app.use(express.cookieParser()); app.use(express.session({ secret: “keyboard cat” })); app.set(‘view engine’, ‘ejs’); app.set(“view options”, { layout: true }); //Handles post requests app.use(express.bodyParser()); //Handles put requests app.use(express.methodOverride()); But still when I ask for req.body.something in my routes I get some error pointing out that body is undefined. Here is … Read more

Client on Node.js: Uncaught ReferenceError: require is not defined

I am writing an application with the Node.js, Express.js, and Jade combination. I have file client.js, which is loaded on the client. In that file I have code that calls functions from other JavaScript files. My attempt was to use var m = require(‘./messages’); in order to load the contents of messages.js (just like I … Read more

What is Express.js?

I am a learner in Node.js. What’s Express.js? What’s the purpose of it with Node.js? Why do we actually need Express.js? How is it useful for us to use with Node.js? What’s Redis? Does it come with Express.js? 10 s 10 1) What is Express.js? Express.js is a Node.js framework. It’s the most popular framework … Read more

Proper way to return JSON using node or Express

So, one can attempt to fetch the following JSON object: $ curl -i -X GET http://echo.jsontest.com/key/value/anotherKey/anotherValue HTTP/1.1 200 OK Access-Control-Allow-Origin: * Content-Type: application/json; charset=ISO-8859-1 Date: Wed, 30 Oct 2013 22:19:10 GMT Server: Google Frontend Cache-Control: private Alternate-Protocol: 80:quic,80:quic Transfer-Encoding: chunked { “anotherKey”: “anotherValue”, “key”: “value” } $ Is there a way to produce exactly the … Read more

Enabling HTTPS on express.js

I’m trying to get HTTPS working on express.js for node, and I can’t figure it out. This is my app.js code. var express = require(‘express’); var fs = require(‘fs’); var privateKey = fs.readFileSync(‘sslcert/server.key’); var certificate = fs.readFileSync(‘sslcert/server.crt’); var credentials = {key: privateKey, cert: certificate}; var app = express.createServer(credentials); app.get(“https://stackoverflow.com/”, function(req,res) { res.send(‘hello’); }); app.listen(8000); When … Read more

Express.js – app.listen vs server.listen

This may be a very basic question but I simply don’t get it. What is the difference between creating an app using Express.js and starting the app listening on port 1234, for example: var express = require(‘express’); var app = express(); //app.configure, app.use etc app.listen(1234); and adding an http server: var express = require(‘express’); var … Read more