0

I'm following through this tutorial: https://thinkster.io/mean-stack-tutorial#introduction. when i'm coming to the end of Beginning Node section, i'm running the command : npm start, but i'm getting error Not found when i'm opening the localhost:3000.

here's the code: angularApp.js

var app = angular.module('flapperNews', ['ui.router']);

app.config(['$stateProvider','$urlRouterProvider',
    function($stateProvider,$urlRouterProvider){
        $stateProvider.state('home',{
            url: '/home',
            templateUrl: '/home.html',
            controller: 'MainCtrl'
        });
        $stateProvider.state('posts', {
          url: '/posts/{id}',
          templateUrl: '/posts.html',
          controller: 'PostsCtrl'
        });
        $urlRouterProvider.otherwise('home');
}]);

app.factory('posts',[function(){
  var o = {
    posts: []
  };
  return o;
}]);

app.controller('MainCtrl', ['$scope','posts',
function($scope,posts){
    $scope.title = '';
    $scope.test = 'Hello world!';
    $scope.posts = posts.posts;
    $scope.addPost = function(){
        if(!$scope.title || $scope.title === '') { return; }
        $scope.posts.push({
          title: $scope.title,
          link: $scope.link,
          upvotes: 0,
          comments: [
            {author: 'Joe', body: 'Cool post!', upvotes: 0},
            {author: 'Bob', body: 'Great idea but everything is wrong!', upvotes: 0}
          ]
        });
        $scope.title = '';
        $scope.link = '';
    };
    $scope.incrementUpvotes = function(post) {
        post.upvotes += 1;
    };

}]);

app.controller('PostsCtrl',['$scope','$stateParams','posts',
    function($scope,$stateParams,posts){
        $scope.post = posts.posts[$stateParams.id];
        $scope.addComment = function(){
          if($scope.body === '') { return; }
          $scope.post.comments.push({
            body: $scope.body,
            author: 'user',
            upvotes: 0
          });
          $scope.body = '';
        };      
    }
]);

index.ejs

<html>
<head>
  <title>Flapper News</title>
  <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.14/angular-ui-router.js"></script>
  <script src="/javascripts/angularApp.js"></script>
  <script type="text/ng-template" id="/home.ejs">
    <div class="page-header">
      <h1>Flapper News</h1>
    </div>
    <div ng-repeat="post in posts | orderBy:'-upvotes'">
      <span class="glyphicon glyphicon-thumbs-up"
        ng-click="incrementUpvotes(post)"></span>
      {{post.upvotes}}
      <span style="font-size:20px; margin-left:10px;">
        <a ng-show="post.link" href="{{post.link}}">
          {{post.title}}
        </a>
        <span ng-hide="post.link">
          {{post.title}}
        </span>
      </span>
      <span>
      <a href="#/posts/{{$index}}">Comments</a>
    </span>
    </div>
    <form ng-submit="addPost()"
      style="margin-top:30px;">
      <h3>Add a new post</h3>
     <div class="form-group">
        <input type="text"
          class="form-control"
          placeholder="Title"
          ng-model="title"></input>
      </div>
      <div class="form-group">
        <input type="text"
        class="form-control"
        placeholder="Link"
        ng-model="link"></input>
      </div>
      <button type="submit" class="btn btn-primary">Post</button>
    </form>
</script>
<script type="text/ng-template" id="/posts.ejs">
  <div class="page-header">
    <h3>
      <a ng-show="post.link" href="{{post.link}}">
        {{post.title}}
      </a>
      <span ng-hide="post.link">
        {{post.title}}
      </span>
    </h3>
  </div>

  <div ng-repeat="comment in post.comments | orderBy:'-upvotes'">
    <span class="glyphicon glyphicon-thumbs-up"
      ng-click="incrementUpvotes(comment)"></span>
    {{comment.upvotes}} - by {{comment.author}}
    <span style="font-size:20px; margin-left:10px;">
      {{comment.body}}
    </span>
  </div>
  <form ng-submit="addComment()"
    style="margin-top:30px;">
    <h3>Add a new comment</h3>

    <div class="form-group">
      <input type="text"
      class="form-control"
      placeholder="Comment"
      ng-model="body"></input>
    </div>
    <button type="submit" class="btn btn-primary">Post</button>
  </form>
  </script>
  <style> .glyphicon-thumbs-up { cursor:pointer } </style>
</head>
<body ng-app="flapperNews">
  <div class="row">
    <div class="col-md-6 col-md-offset-3">
      <ui-view></ui-view> 
    </div>
  </div>
</body>
</html>

Thanks a lot!

7
  • Are you sure your server is running? Could you show your server side code? Commented May 12, 2016 at 13:13
  • In the beginning node section, iv'e created the application files with express, and after that i added the code in that question. Commented May 12, 2016 at 14:27
  • I didn't touch the server side code Commented May 12, 2016 at 14:28
  • Did you check if the server side was working before? Don't you have any erros in the server log? Commented May 12, 2016 at 15:42
  • No. there are no errors out there Commented May 12, 2016 at 21:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.