C9 not returning my api call information in browser but it does in terminal


Hey guys,

I’m trying to access my api information in my angular page but it says 404 found.

My angular code is:

    app.controller("dataCtrl", function($scope, $http) {
  $http.get('/api/jobs').then(function (resp) {
    $scope.data = resp.data;
  }, function(error,resp) {
    console.log(error, resp);

My mysql.js is

app.get('/api/jobs', function(req, res, next) {
  connection.query('SELECT * FROM jobs ORDER BY id ASC', function(err, results) {
      if (err) {
          console.log('There was a problem reading from jobs database :' + err.stack);
          res.sendStatus(500).send('There was a problem reading from jobs database');

      console.log('results:', results);

when I do

curl localhost:3000/api/jobs

in terminal it does return the information but when I do




Nothing is returned, what am I doing wrong?


I’ve tried to diagnose it, but can’t seem to find the problem. Do you have a link to the workspace? Is there any stacktrace on the server or the client?

Thanks and I’ll try to figure it out as soon as I have that! :slight_smile:


Link to my workspace code or project?



Looking at your code, I have a few questions: how is the server running? The error page is an Apache error page, but you’re writing NodeJS. So is the mysql.js file being run with “node mysql.js”, or are you just using the Apache runner (which I believe doesn’t support node). Common practice is to write code outside of the node_modules folder and load modules in that code, so I’m wondering which files you created and which ones were already there?


My mysql.js is being ran by node mysql.js.

I created the index.html, the index.js for it, and style.css, and mysql.js


Then the only reason I could imagine is that Apache is handling the request before Node, so it sends an error page and stops any other code running. Could you possibly try running just the node server by itself?


Silly quesiton…how would I do that?


There are no silly questions. I would suggest closing all Apache runners you have open, and then checking if the error still happens:

Should look something like this, if the Run button says Stop, press it.
Then make sure mysql.js is running using node mysql.js, and go to api/jobs.