Skip to content
Advertisement

Tag: express

Pug – generating Select and Options

I am new to Pug and I am trying to generate a Select set of Options like this: However the result I get, in the rendered page, is an empty select input followed by the list of options as text Answer Indents the code https://pugjs.org/language/iteration.html

Can’t delete cookie in express

Pretty simple. I set a cookie like so in my /user/login route: I’ve already set my secret for cookie-parser: Pretty basic stuff. Everything is working great insofar as I’m able to retrieve whatever I stored in the cookie: This middleware is called before anything else, so for the sake of the argument “Cookie exists!” is always logged in my console

Express.Static not working for subdirectory

Express.static is working great for any view in root directory, but it breaks when I add a subdirectory. Works: Doesn’t Work: I’m guessing __dirname is changed to whatever directory the get request is made from, but I just want to use the root (/public) directory for all static requests. Answer Use it this way:

In Express.js, should I return response or not?

For Express.js 4.x I can’t find wether I should return the response (or next function) or not, so: This: Or this: And what is the difference? Answer You don’t. The (req, res) signature tells express this is the last function in the chain, and it does not expect a return value from this function. You can add a return statement,

how to delete cookie on logout in express + passport js?

I want to “delete cookies on logout”. I am not able to do that. I googled for answer and found following ways: Assign new date of expiration to cookie res.cookie(‘connect.sid’, ”, {expires: new Date(1), path: ‘/’ }); Delete cookie using below lines res.clearCookie(‘connect.sid’, { path: ‘/’ }); I tried both ways individually but they do not delete the cookie. Here

Advertisement