A
A
azatbikmaev2017-10-18 17:41:10
JavaScript
azatbikmaev, 2017-10-18 17:41:10

Node js + express how to set cookies via function?

There is a server on Node js with express,
I have a code by which I calmly set cookies for the user

app.use('/',function(req, res, next){
res.cookie('userid', '', { expires: new Date(Date.now() + 900000), httpOnly: true });
});

but how to assign cookies in a function
function authclients(){
app.use('/',function(req, res, next){
res.cookie('userid', '', { expires: new Date(Date.now() + 900000), httpOnly: true });
});
}

So I can’t do it, who knows, help me solve a problem that I can’t figure out.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Zhivagin, 2017-10-18
@azatbikmaev

app.use('/', authclients(req, res) );

function authclients(req, res) {
res.cookie('userid', '', { expires: new Date(Date.now() + 900000), httpOnly: true });
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question