Skip to Main Content
Write Modern Web Apps with the MEAN Stack: Mongo, Express, AngularJS, and Node.js
book

Write Modern Web Apps with the MEAN Stack: Mongo, Express, AngularJS, and Node.js

by Jeff Dickey
September 2014
Intermediate to advanced content levelIntermediate to advanced
256 pages
5h 25m
English
Peachpit Press
Content preview from Write Modern Web Apps with the MEAN Stack: Mongo, Express, AngularJS, and Node.js

Chapter 4. Building a Node.js API

In the previous chapter, you built a fully functioning Angular app for posting status updates. In this chapter, you will build an API for it to get a list of all the posts and to make a new post. The endpoints will be as follows:

GET /api/posts returns a JSON array of all the posts. This is similar to what you had in $scope.posts.

POST /api/posts expects a JSON document containing a username and post body. It will save that post in MongoDB.

The Stock Endpoint

To start, you’ll use Node.js and Express to build a stock /api/posts endpoint. First, inside a new folder, create a package.json file like the following:

{  "name": "socialapp"}

The name can be anything you want, but try to ensure it doesn’t conflict ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Node.js, MongoDB, and AngularJS Web Development

Node.js, MongoDB, and AngularJS Web Development

Brad Dayley

Publisher Resources

ISBN: 9780133962369Purchase book