Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

sending api with limited fields in express

/*in controller
Api call url {{baseUrl}}/tours?fields=name,duration,price
*/

export.getAllTours= async(req,res)=> {
try{
  if(req.query.fields){
  const fields= req.query.fields.split(",").join(' ');
   let query= query.select(fields); //name duration price
  }
  
}catch(err){
  console.log(err)
}
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: flatten a nested json 
Javascript :: string split into three non empty combination js 
Javascript :: How to access a preexisting collection with Mongoose 
Javascript :: Using javascript code in Jade views - if(variable) shows undefined instead of passing 
Javascript :: upload node js 
Javascript :: promsie js 
Javascript :: nextjs app wdyr 
Javascript :: Sequelize conditional shorthands 
Javascript :: javascript datamatrix parser 
Javascript :: audio js fast 
Javascript :: chat v2 msg and time good 
Javascript :: code with mosh swipable react native not working 
Javascript :: javascript server side 
Javascript :: Creating New Transaction Object for blockchain 
Javascript :: how to get content disposition from header jquery 
Javascript :: difference between push and pop in javascript 
Javascript :: append vs appendchild 
Javascript :: board in javascript 
Javascript :: save to text or html file very good 
Javascript :: JavaScript get div height dynamically without jQuery 
Javascript :: react mui pagination change text color site:stackoverflow.com 
Javascript :: Backbone View Template 
Javascript :: javascript enter key 
Javascript :: discord.js create a private channel 
Javascript :: A Note on Jest & React 
Javascript :: react get variable from child component 
Javascript :: react tutorial app 
Javascript :: mounting in react 
Javascript :: event solidity 
Javascript :: Remove uploaded file in jquery 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =