简体   繁体   中英

NodeJS invalid syntax in function

SyntaxError: Invalid or unexpected token line 5

I cant seem to find what is missing or where the syntax is wrong

const getData = () => {
    return new Promise((resolve) => {
        const connection = createConnection();
        const sqlQuery = fs.readFileSync('./file.sql').toString();
      ​
        connection.connect((err) => {
            if (err) {
                console.log('Error connecting to Db:' + err);
                return;
            }
            console.log('Database connection established.');
            connection.query(sqlQuery, (err, results, fields) => {
                if (err) throw err;
                connection.end((err) => {
                    if (err) {
                        console.log(err);
                    }
                    console.log('Database connection closed.');
                    resolve(results);
                });
            });
        });
    });
};

尝试通过退格来删除line 5 ,以便您的新第 5 行现在是connection.connect((err) => {复制和粘贴代码时可以创建称为“隐形字符”的东西。请注意,当您将鼠标悬停在浏览器上的开发工具中的语法错误它给你\​ 。这是另一篇关于 stackoverflow 的文章讨论,可能会有帮助: here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM