watsonx Assistant

watsonx Assistant

Conversational AI for fast and friendly customer care

 View Only

Syntax Error on node.js access MySql

  • 1.  Syntax Error on node.js access MySql

    Posted Wed October 07, 2020 08:11 PM
    Edited by System Admin Fri January 20, 2023 04:34 PM
    Hello Friends.

    I am trying to develop a function which will access my MySql db and return some rows (that's all).

    But I am facing a syntax error and I am not getting to find where this error is.

    Please find below my code and the message erro.

    Thank you in advance for any hint.

    /**
    *
    * main() será executado quando você chamar essa ação
    *
    * @param As ações do Cloud Functions aceitam um único parâmetro, que deve ser um objeto JSON.
    *
    * @return A saída dessa ação, que deve ser um objeto JSON.
    */

    function main(params) {

    const mysql = require('mysql');
    // var connection = sql.createPool({
    const con = mysql.createPool({
    host: 'xxxxxxxxxxxxxxxxxx',
    user: 'xxxxxxxxxxxxxxxxx',
    password: 'xxxxxxxxxxxxxxxx',
    database: 'xxxxxxxxxxxxxxxx
    });

    con.connect(function(err) => {
    if (err) {
    console.log('Erro connecting to database...', err)
    return
    }
    console.log('Connection established!')
    })

    con.query('SELECT * FROM db_a43aea_frenew.clientes where Owner = 208', (err, rows) => {
    if (err) throw err

    console.log('NomeDoCliente: ', rows, '\n\n')
    })

    con.end((err) => {
    if(err) {
    console.log('Erro to finish connection...', err)
    return
    }
    console.log('The connection was finish...')
    })
    return { message: 'Hello World po...........' };
    }

    And The error message :

    Resultados:
    {
      "error": "Initialization has failed due to: SyntaxError: Unexpected token =>\n    at initializeActionHandler (/nodejsAction/runner.js:63:80)\n    at doInit (/nodejsAction/src/service.js:174:16)\n    at initCode (/nodejsAction/src/service.js:93:24)\n    at /nodejsAction/platform/platform.js:125:17\n    at Layer.handle [as handle_request] (/node_modules/express/lib/router/layer.js:95:5)\n    at next (/node_modules/express/lib/router/route.js:137:13)\n    at Route.dispatch (/node_modules/express/lib/router/route.js:112:3)\n    at Layer.handle [as handle_request] (/node_modules/express/lib/router/layer.js:95:5)\n    at /node_modules/express/lib/router/index.js:281:22\n    at Function.process_params (/node_modules/express/lib/router/index.js:335:12)"
    }
    Logs:
    [
      "2020-10-07T23:59:15.168325Z    stderr: Error during initialization: SyntaxError: Unexpected token =>",
      "2020-10-07T23:59:15.168390Z    stderr: at initializeActionHandler (/nodejsAction/runner.js:63:80)",
      "2020-10-07T23:59:15.168397Z    stderr: at doInit (/nodejsAction/src/service.js:174:16)",
      "2020-10-07T23:59:15.168403Z    stderr: at initCode (/nodejsAction/src/service.js:93:24)",
      "2020-10-07T23:59:15.168408Z    stderr: at /nodejsAction/platform/platform.js:125:17",
      "2020-10-07T23:59:15.168413Z    stderr: at Layer.handle [as handle_request] (/node_modules/express/lib/router/layer.js:95:5)",
      "2020-10-07T23:59:15.168419Z    stderr: at next (/node_modules/express/lib/router/route.js:137:13)",
      "2020-10-07T23:59:15.168425Z    stderr: at Route.dispatch (/node_modules/express/lib/router/route.js:112:3)",
      "2020-10-07T23:59:15.168430Z    stderr: at Layer.handle [as handle_request] (/node_modules/express/lib/router/layer.js:95:5)",
      "2020-10-07T23:59:15.168436Z    stderr: at /node_modules/express/lib/router/index.js:281:22",
      "2020-10-07T23:59:15.168441Z    stderr: at 


    ------------------------------
    Eduardo Gameiro
    ------------------------------
    #WatsonAssistant