节点 js 应用程序中的弃用警告
Posted
技术标签:
???????? js ????????????????:DeprecationWarnings in nodejs application ??????:2020-03-08 06:58:07 ??????:????.js
const express=require('express')
const router=express.Router()
const gravatar=require('gravatar')
const bcrypt=require('bcryptjs')
const check,validationResult =require('express-validator/check')
const User=require('../../models/User')
//@route POST api/users
//@desc Register user
//@access public
router.post('/',[
check('name','Name is required').not().isEmpty(),
check('email','please include a valid email').isEmail(),
check('password','please enter password with more than 6 characters').isLength(min:6)
],async(req,res)=>
const errors=validationResult(req);
if(!errors.isEmpty())
return res.status(400).json(errors:errors.array())
const name,email,password=req.body;
try
//see if the user exists
let user = await User.findOne( email: email )
//if record exists in DB
if (user)
return res.status(400).json( errors: [ msg: "user already exists" ] );
//get users gravatar
const avatar=gravatar.url(email,
s:'200', //size
r:'pg', //rating of image
d:'mm' //gives a default image
)
user=new User(
name,
email,
avatar,
password
)
//encrpyt password
const salt=await bcrypt.genSalt(10) // 10-no of rounds.more the better
user.password=await bcrypt.hash(password,salt); //coverts to hash pass
await user.save();
//return jsonwebtoken
res.send('User registered')
catch(e)
console.log(e.message)
res.status(500).send('server error')
res.send('User route')
)
module.exports=router;
????????,?????????
(node:1022) UnhandledPromiseRejectionWarning: ?? [ERR_HTTP_HEADERS_SENT]: ????????????? ? ServerResponse.setHeader (_http_outgoing.js:464:11) ? ServerResponse.header (/Users/udayshetty/Desktop/MERN app/node_modules/express/lib/response.js:771:10) ? ServerResponse.send (/Users/udayshetty/Desktop/MERN app/node_modules/express/lib/response.js:170:12) ? /Users/udayshetty/Desktop/MERN app/routes/api/users.js:60:9 ? processTicksAndRejections (internal/process/task_queues.js:85:5) (node:1022) UnhandledPromiseRejectionWarning:????????????????? catch ?????????????,?????? .catch() ?????? (????:1) (??:1022)[DEP0018] DeprecationWarning:????????????????,???? Promise ????????????? Node.js ???
??????:
?????res.send('User route')
,?????????????????,???????
users.js ??? 60 ?? res.send('User route'),???????
???????
Error: Can't set headers after they are sent to the client?????
?????1?:
??????? HTTP ????????????????/?????,?????????????,???????????? http ??,????????????????????????,????????????
????? res.send('User route')?
?????????
????:
以上是关于节点 js 应用程序中的弃用警告的主要内容,如果未能解决你的问题,请参考以下文章
Mac Catalyst 中的弃用警告,但仅在 Objective-C 中,而不是在 Swift 中
sklearn MiniBatchKMeans 中的弃用警告