bloppit bloppit - 1 year ago 93
Node.js Question

How do I return the static data?

I am working on a project, a course-rating API. We have been provided with a finished angular application to work with it. We're not expected to change the Angular app.

The first tasks I was asked to set up the routes, with one of them being

GET /api/courses route

Task two then says:

Update the GET /api/courses route to return static data.
Return an array of object literals with "_id" and "title" properties
You should now be able to run the application (using npm start), browse to http://localhost:5000, and see your static data in the AngularJS application's "Courses" screen.

I don't understand what this means, where are we returning the data from? This is only step 2 of the project instructions. The mongo database and seed data isn't mentioned until steps 4,5 and 6.

These are my routes set up in my current index.js file:

// include routes
var routes = require('./routes');
// setup our static route to serve files from the "public" folder
app.use('/', express.static('public'));

app.use('/api', routes.users);

And this is my route in my routes folder:

//load express
var express = require('express');
//create router
var router = express.Router();

// Returns the Course "_id" and "title" properties
router.get('/courses', function(req, res, next){
//Where is the date coming from?
//res.json('data/data.json', [{title:}, {_id:}]);


In the 'before you start' section of the project it does say this:

"When you’re ready, you can configure the provided AngularJS client side application to use your REST API instead of the in-browser mock data.
- Open the public/index.html HTML file into the editor of your choice.
- Change the constants.useMockData property value to false.
- Run the application (by using the npm start command) and browse at
http://localhost:5000. If you already had the application loaded into
your browser, be sure to refresh the page.
- The “mock data” alert at the top of the page should no longer be
visible, indicating that the AngularJS application is now using your

I did that way before I started.

I don't understand what I need to be doing here. As you can see from my route code!

I'd really appreciate any help please, I understand this isn't the clearest of questions, I apologise. My repo for the project is here:

The full project instructions are in the readme.

Answer Source

They're asking you to return some sample data in that instruction.

Just so you will see some data on the client side and to make sure that your routes are working. Like a small test.

I'm guessing that in the further steps they'll ask you to fetch the data from the DB and return it instead of the sample data.

Am I even close to what you want in an answer?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download