req.header vs req.headers in Express

The problem arises because in the HTTP protocol, headers are case-insensitive. This means that content-type, Content-Type, and coNTEnt-tYPe all refer to the same header, and the Express framework needs to be able to handle any of them. The different between req.headers (the object) and req.header (the function) is simply this: If you want to get … Read more

ExpressJS & Websocket & session sharing

I found this works for me. Not sure it’s the best way to do this though. First, initialize your express application: // whatever your express app is using here… var session = require(“express-session”); var sessionParser = session({ store: session_store, cookie: {secure: true, maxAge: null, httpOnly: true} }); app.use(sessionParser); Now, explicitly call the session middleware from … Read more

Sequelize – SQL Server – order by for association tables

From Sequelize offical docs: // Will order by an associated model’s created_at using an association object. (preferred method) [Subtask.associations.Task, ‘createdAt’, ‘DESC’], // Will order by a nested associated model’s created_at using association objects. (preferred method) [Subtask.associations.Task, Task.associations.Project, ‘createdAt’, ‘DESC’], By referring above syntax, Update your order option like below User.findById(uID, { include: [{ model: sequelize.models.userProfile … Read more

How to use GridFS to store images using Node.js and Mongoose

I was not satisfied with the highest rated answer here and so I’m providing a new one: I ended up using the node module ‘gridfs-stream’ (great documentation there!) which can be installed via npm. With it, and in combination with mongoose, it could look like this: var fs = require(‘fs’); var mongoose = require(“mongoose”); var … Read more

Nodejs EJS helper functions?

Yes, in Express 3 you can add helpers to app.locals. Ex: app.locals.somevar = “hello world”; app.locals.someHelper = function(name) { return (“hello ” + name); } These would be accessible inside your views like this: <% somevar %> <% someHelper(‘world’) %> Note: Express 2.5 did helpers differently.

TypeError: req.session.regenerate is not a function using Passport

Am doing the same course, fix is there on udemy. From Udemy : Passport v.0.6.0 is currently broken due to an incompatibility: https://github.com/jaredhanson/passport/issues/907 The maintainer suggests using the latest v0.5.0 until a fix is pushed out. Use: npm uninstall passport npm install [email protected] this worked fine for me.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)