JavaScript Node.js (Openshift) express response not working openshift node express

I am using OpenShift and Node.js I am trying to get the average - rating for each result but I cant get the response to work even though the console reports correctly. I get 3.9454323 into the console , but when I git localhost:3002/getM/1 the response is blank.

app.get('/getM/:movieId', function(request,response) {
  var movieId = request.params.movieId;
  var connection = mysql.createConnection({
    host: process.env.OPENSHIFT_MYSQL_DB_HOST || 'localhost',
    user: process.env.OPENSHIFT_MYSQL_DB_USERNAME || 'root',
    password: process.env.OPENSHIFT_MYSQL_DB_PASSWORD || '',
    port: process.env.OPENSHIFT_MYSQL_DB_PORT || '3306',
    database: 'test'
  });
  connection.connect(function (err) {
    if (err) {
      console.error('error connecting: ' + err.stack);
      response.send("error connecting to database");
      return;
    }
    console.log('connected as id ' + connection.threadId);
  });
  connection.query('SELECT * FROM `ratings` WHERE `movieId` = ?',[movieId], function(err, result) {
    if (err) {
      response.send(err);
    }
    var sum = 0;
    result.forEach(function(movie) {
      sum += movie["rating"];
      console.log(sum);
    });
    console.log(sum/result.length);
    response.send(sum/result.length);
  });
});
Answer:1

I try to post a form using ajax the current code does not really work. When I press the save button the form get submitted n + 1 times. i.e After refreshing the page it submit once, next time I submit ...

I try to post a form using ajax the current code does not really work. When I press the save button the form get submitted n + 1 times. i.e After refreshing the page it submit once, next time I submit ...

  1. submit form with javascript
  2. submit form with jquery
  3. submit form with ajax
  4. submit form with button
  5. submit form with link
  6. submit form with anchor
  7. submit form with a tag
  8. submit form with button outside form
  9. submit form with enter key
  10. submit form with get method
  11. submit form with php
  12. submit form with react
  13. submit form with input type button
  14. submit form with fetch
  15. submit form with curl
  16. submit form with selenium python
  17. submit form with enter key react
  18. submit form with value javascript
  19. submit form with multiple inputs
  20. submit form with python requests

I am developing a chatbot using Dialogflow, I would like to throw a message to user when the chatbot doesn't understand the user input for three times in a row and for the forth time respond with a ...

I am developing a chatbot using Dialogflow, I would like to throw a message to user when the chatbot doesn't understand the user input for three times in a row and for the forth time respond with a ...

  1. throw custom message java
  2. throw custom message c#
  3. throw custom exception message c#
  4. throw custom exception message java
  5. throw custom error message c#
  6. throw custom error message java
  7. powershell throw custom message
  8. throw exception custom message
  9. throw custom error message
  10. sql server throw custom message
  11. throw new exception custom message
  12. throw new exception custom message c#
  13. sql throw custom error message
  14. javascript throw custom error message
  15. sql throw with custom message

I have defined a function as following : function getCurrentComponent(){ if($rootRouter._currentInstruction){ return $rootRouter.recognize($rootRouter._currentInstruction.urlPath).then(...

I have defined a function as following : function getCurrentComponent(){ if($rootRouter._currentInstruction){ return $rootRouter.recognize($rootRouter._currentInstruction.urlPath).then(...

  1. function handle to symbolic matlab
  2. function handle to string matlab
  3. function_handle with value
  4. function handle with multiple variables matlab
  5. function handle with two variables
  6. function_handle with value matlab
  7. function handle with parameters matlab
  8. string handling function
  9. function handle for loop matlab
  10. function handle with multiple outputs
  11. handle to function matlab
  12. function handle to symbolic
  13. function handle with multiple variables
  14. function handle to double
  15. function handle with arguments matlab
  16. function handle to matrix
  17. function handle with array
  18. function handle to

The following Promise behaves as expected, the Promise in the return statement gets fulfilled and the then right afterwards gets executed before the last call of then: (new Promise(resolve => ...

The following Promise behaves as expected, the Promise in the return statement gets fulfilled and the then right afterwards gets executed before the last call of then: (new Promise(resolve => ...