Express session not sending cookie to client side when nodejs app is deployed on nginx live server

I have nodejs application cookies working fine on localhost but when i deploy it on nginx live server cookie not set on client side. Please anyone to assist me on this matter. Below is the code am using to set up express session with cookie.

//express-session configurations
const storeOptions = {
  host: process.env.DB_HOST,
  port: process.env.DB_PORT,
  user: process.env.DB_USER,
  password: process.env.DB_PASS,
  database: process.env.DB_NAME,
  clearExpired: true,
}; //db store

const sessionStore = new MySQLStore(storeOptions);
const sessionOptions = {
  key: process.env.SESSION_KEY,
  secret: process.env.SESSION_SECRET,
  resave: false,
  saveUninitialized: false,
  store: sessionStore,
  cookie: {
    maxAge: 1000 * 60 * 60 * 12, //12hours

if (app.get("env") === "production") {
  app.set("trust proxy", 1); // trust first proxy = true; // serve secure cookies


app.use(passport.initialize()); //initialize passport
app.use(passport.session()); //initialize session with passport

Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Did it resolve?

Hi @samunyi90,

Have you checked the logs?

The server-side generate a HMAC signature of the session ID which is used by session-express, if it hasn’t been created correctly the client-side doesn’t will work properly.

You can uses the debug-module to output debug messages:

DEBUG=express-mysql-session* node your-app.js

I would be happy assist you,

Sergio Turpín

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

This comment has been deleted