Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
Why doesnt cookieparser return value?

My console.log(req.cookies) returns [Object: null prototype] {}. I don't know where is a problem. It receives variables correctly from Reactjs. JWT is working correctly too, but command: res.cookie('token', token); doesn't work. When I start program it returns: [Object: null prototype] {}. My question is: Why is it returning me [Object: null prototype] {}. Why there is empty {} without any value?

index.js:

const express = require('express')
const cookieparser = require("cookie-parser");
const cors = require('cors')
const jwt = require('jsonwebtoken')
const mongoose = require('mongoose')
const LoginModel = require('./db.js')
const Login = require('./db.js');
const app = express()
app.use(express.json())
app.use(cookieparser());
app.use(cors())
mongoose.connect('mongolink',{
    useNewUrlParser: true, useUnifiedTopology: true
})
app.post('/logging', async (req,res) =>{
    const username = req.body.username
    const password = req.body.password
    if( username!=='' && password!=='')
    {
        const Find = await LoginModel.findOne({username:username}).exec()
        console.log(Find);
        if(Find!== null)
        {
            const token = jwt.sign({ username}, 'supersecret');
            res.cookie('token', token);
            console.log(req.cookies);
        }
      }
})
app.listen(3001)

Login.js :

import React, {useState} from 'react'
import './App.css';
import Axios from 'axios'
import {Link} from 'react-router-dom'
function App() {
  const [username,setusername] = useState('')
  const [password,setpassword] = useState('')
  const Login = () => {
    Axios.post('http://localhost:3001/logging', {
      username:username,
      password: password
    })
  }
  return (
    <div className="App">
      <label>username</label>
        <input type='text' onChange={
          (event) => {
            setusername( event.target.value )
          }
        }/>
        <label>haslo</label>
      <input type='password' onChange={
       (event) =>{
         setpassword( event.target.value )
       } 
      }/>
      <button onClick={Login}>Login</button>
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!