OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

TypeError: Cannot destructure property id of req.params as it is undefined

  • Thread starter Thread starter caged_raven_wings
  • Start date Start date
C

caged_raven_wings

Guest
I'm trying to get a user profile from a database and return it as a json object when the profile url (localhost:3000/Profile/1) is ran. but i am getting this error: TypeError: Cannot destructure property id of req.params as it is undefined.

here is the code in the express server.

Code:
const express = require('express');
const bodyParser = require('body-parser');
const bcrypt = require('bcryptjs');
const cors = require('cors');
const knex = require('knex');

const app = express();
app.use(cors());
app.use(bodyParser.json());


app.get('/Profile/:id', (res,req) =>{
    const {id} = req.params;
    db.select('*').from('user').where({id})
    .then(user => {
    res.json(user[0])})
})

i used postman to send the get request.

<p>I'm trying to get a user profile from a database and return it as a json object when the profile url (localhost:3000/Profile/1) is ran. but i am getting this error: <strong>TypeError: Cannot destructure property <em>id</em> of <em>req.params</em> as it is undefined.</strong></p>

<p>here is the code in the express server.</p>

<pre><code>const express = require('express');
const bodyParser = require('body-parser');
const bcrypt = require('bcryptjs');
const cors = require('cors');
const knex = require('knex');

const app = express();
app.use(cors());
app.use(bodyParser.json());


app.get('/Profile/:id', (res,req) =>{
const {id} = req.params;
db.select('*').from('user').where({id})
.then(user => {
res.json(user[0])})
})

</code></pre>

<p>i used postman to send the get request.</p>
 

Latest posts

Top