asu*_*sus 0 node.js express unexpected-token
我的应用程序每次到达此行时都会崩溃:
const {name, price} = req.query;
^
Run Code Online (Sandbox Code Playgroud)
似乎无法找到确切的答案..错误日志
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:140:18)
at node.js:1043:3
Run Code Online (Sandbox Code Playgroud)
背景:
app.get('/products/add' , (req, res) => {
const {name, price} = req.query;
const INSERT_PRODUCTS_QUERY = `INSERT INTO products (name, price) VALUES ('${ name }', ${ price })`;
connection.query(INSERT_PRODUCTS_QUERY, (err,results) => {
if(err)
{
return res.send(err);
}
else
{
return res.send('succesfully added product');
}
});
});
Run Code Online (Sandbox Code Playgroud)
根据node.green,使用primitives语法的对象解构在Node.JS v6.4.0之后工作,并抛出Unexpected Token {下面的Node.js版本.
此外,对象rest/spread属性仅在Node v8.6.0中开箱即用.它在带有--harmony标志的v8.2.1中工作,并抛出Unexpected Token ...下面的Node.js版本.
| 归档时间: |
|
| 查看次数: |
503 次 |
| 最近记录: |