簡體   English   中英

Nodejs SyntaxError:意外令牌{

[英]Nodejs SyntaxError: Unexpected token {

我正在按照教程學習,所以我無法理解這個錯誤,因為我已經仔細檢查過,很確定我的新手再次發動攻擊...

SyntaxError: Unexpected token {
    at new Script (vm.js:51:7)
    at createScript (vm.js:138:10)
    at Object.runInThisContext (vm.js:199:10)
    at Module._compile (module.js:624:28)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
[nodemon] app crashed - waiting for file changes before starting.

..

module.exports = function() {

  this.getNoticias(connection, callback){
    connection.query('SELECT * FROM noticias', callback);
  }

  return this;
}

在此處輸入圖片說明

您用來聲明函數的表達式無效。

為了聲明一個函數,您應該使用this.getNoticias = function(...)

因此完整的代碼應如下所示:

this.getNoticias = function(connection, callback){
    connection.query('select * from noticias', callback);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM