Sunday 23 August 2020

Needing some help of creating my app?

recently i've been learning Reactjs and i've missunderstand some concepts for structure my web app so i just make some basics stuff like i create my react app and doing server part and connecting to mongodb ect there is No probleme but i see some app with various inststrucure and that what make me confiused a little bed like i've found app contain middlewar and controller and validation partinside those files (Controller file ) i fount some thing like thatasync create(req, res) {const task = new TaskModel(req.body);await task.save().then(response => {return res.status(200).json(response);            }).catch(error => {return res.status(500).json(error);            });    }and that make me wondring about why should i use async and await and i have a question herewhy should i use asynchronous function meanwhile i disscover some apps just do thisrouter.route('/add').post((req, res) => {const username = req.body.username;const newUser = new User({username});  newUser.save().then(() => res.json('User added!')).catch(err => res.status(400).json('Error: ' + err));});like this concept just add express router and recieve the body ect.. and he's good with that structurebut i found in first example that routes and validation organized well , but the point here should i use Contoller and seprate the routes part and validateseconde point i do some search about validation body of course i found exprees validation but there is No Turnout for it and that's to make me wondring why there's so much validate thier inputs requestfor knowing i know Monngose doing this part like the max for the propety value and should it req or Not and stuff like that so should i be good with that with No need for validateor sprate routes folder and making middleware and using asynchronous concept and i saw a lot of project course there No one validae with express or use like first example structurei'm disappointed and don't know what should i do , so is there is any way to see the best practise for structure my wep app and what should i do and what shouldn'tthanks ()

Submitted August 24, 2020 at 07:07AM by Adamqaram

No comments:

Post a Comment