1

I have been following this tutorial on thinkster.io:

https://thinkster.io/mean-stack-tutorial/

Everything works fine until I get to the section where we setup mongoose, then I start to hit problems.

First of all in the section "Creating Schemas with Mongoose" it says:

"Connect to our local MongoDB instance by adding the following code into our app.js file:"

But this is unclear - what do they mean by "our" app.js file - we no longer have an app.js that we created as we renamed it to angularApp.js - the only app.js file is the one generated by express/npm which is in the /views/ folder and is full of express configurations. I personally added the code to this file but am unsure if they meant for us to add it to /public/javascripts/angularApp.js

Secondly, in the "Creating our first route" section, the tutorial instructs us to add the code to routes/index.js but again this file is already populated with express routes and the tutorial is unclear as to whether we append this file with the new route for /posts or to remove the existing express route and add the /posts route instead.

Either way, the result is when I attempt to post the first data to mongodb via curl or postman it results in a 404, indicating the route is not working.

Any help appreciated - there is no comment section on the site for asking questions or troubleshooting, so I am hoping stackoverflow can fill in the gaps :)

syymza
  • 679
  • 1
  • 8
  • 23
Paladine
  • 11
  • 2
  • Angular is on the client side. Presumably Mongo access is on the *server* side. – Dave Newton May 09 '15 at 14:59
  • Yes MongoDB is running as a service - not sure what your point was? – Paladine May 09 '15 at 16:26
  • The Angular app js file is the client app. Running on the client. Putting Mongo initialization/schema code in there wouldn't make any sense. – Dave Newton May 09 '15 at 17:09
  • I didnt add the code to the angular app js file - as I stated in the original post, I added it to the app.js file in the views/ folder. My point was that the tutorial wasn't clear on this as in the previous section we changed the name of our app.js to angularApp.js and moved it. – Paladine May 09 '15 at 18:15
  • Yes. You also said you didn't know if it was the right thing to do, and I addressed that concern, and explained why. Not sure what your issue is with this. – Dave Newton May 09 '15 at 18:31
  • Hey @Paladine do you still have pro account on thinkster? – famas23 Dec 02 '18 at 18:50

1 Answers1

4

Here's my code: https://github.com/jakblak/thinkster_mean_app

It's more organized then the original and commented.

venturz909
  • 330
  • 2
  • 12
  • that was a lot of help, thank you. Sorry I can't upvote you yet. – Paladine May 10 '15 at 00:05
  • I am having another problem now. My comment upvotes are not writing to the database, I am getting a 500 error instead: TypeError: Cannot read property 'upvote' of undefined at D:\www\flapper-news\routes\index.js:75:16 Here is the section from index.js: router.put('/posts/:post/comments/:comment/upvote', function (req, res, next) { req.comment.upvote(function (err, comment) { if (err) { return next(err); } res.json(comment); }); }); – Paladine May 10 '15 at 11:38
  • I updated the files. Not sure if this will fix your error though. There was a missing views folder and missing user.js file. – venturz909 May 10 '15 at 13:24
  • I notice in your branch you have 2x $scope.incrementUpvotes in your PostsCtrl? Can you confirm that your comments upvoting registers in mongodb? – Paladine May 10 '15 at 13:55
  • here is my project on Git https://github.com/thinkprivacy/MEAN - I can't see why I am getting the 500 error, my code looks the same as yours – Paladine May 10 '15 at 14:15
  • try working from my updated files. Download then do: npm install - bower install - node app – venturz909 May 10 '15 at 15:20
  • my latest commit is working, I had simply not added the router.param() for comments – Paladine May 10 '15 at 15:39