Skip to content

Commit 99bac7d

Browse files
committed
Log URLs, add scripts, simplify async
1 parent 66ff6be commit 99bac7d

File tree

5 files changed

+84
-72
lines changed

5 files changed

+84
-72
lines changed

Diff for: README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A demo of what an equivalent REST API and GraphQL interface look like. This code
66

77
To install you'll want to run `npm install` or `yarn` to install all of the Node modules.
88

9-
Additionally, you'll need to have a copy of [MongoDB](https://www.mongodb.com/) running. If you're on OSX you can use [Homebrew](https://brew.sh/) to install MongoDB by running: `brew install mongodb`. That should also start the database server in the background, as well. If it's not running you can run `brew services stop mongodb` to start it.
9+
Additionally, you'll need to have a copy of [MongoDB](https://www.mongodb.com/) running. If you're on OSX you can use [Homebrew](https://brew.sh/) to install MongoDB by running: `brew install mongodb`. That should also start the database server in the background, as well. If it's not running you can run `brew services start mongodb` to start it.
1010

1111
You'll also want to populate the database with some data to test your queries. You can do this by running the `mongo testdb` command on the command-line and executing the following commands to create a new database, some collections, and the data inside of them:
1212

@@ -21,10 +21,8 @@ By default the servers are expecting to find data on your local computer in a da
2121

2222
## Data Models
2323

24-
2524
Our data models representing the MongoDB database are in `models.js`. We use [Mongoose](http://mongoosejs.com/) to do the object modeling and provide a convenient way of accessing and mutating the data in the MongoDB collections.
2625

27-
2826
## REST API
2927

3028
The REST API is implemented using [Node Express](https://expressjs.com/) and provides a couple endpoints for accessing user data.

Diff for: graphql-server.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ server.use(
5959
)
6060

6161
// Start the application, listening on port 3000
62-
server.listen(3000)
62+
server.listen(3000, () =>
63+
console.log(`Listening on port 3000.
64+
65+
http://localhost:3000/graphql
66+
`)
67+
)

Diff for: package-lock.json

+64-64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"description": "A demo of what an equivalent REST API and GraphQL interface look like.",
55
"main": "graphql-server.js",
66
"scripts": {
7+
"start": "node graphql-server.js",
8+
"start-rest": "node rest-server.js",
79
"prettify": "prettier --write *.js"
810
},
911
"author": "John Resig <[email protected]>",

Diff for: rest-server.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,18 @@ server.get('/users', (req, res) => {
6666
// Return the array of users to the client (automatically
6767
// serialized as a JSON string) We need to wait for all
6868
// of the Promises to resolve for all of the users.
69-
res.send(
70-
await Promise.all(users.map(async user => await filterFields(req, user)))
71-
)
69+
res.send(await Promise.all(users.map(user => filterFields(req, user))))
7270
})
7371
})
7472

7573
// Start the application, listening on port 3000
76-
server.listen(3000)
74+
server.listen(3000, () =>
75+
console.log(`Listening on port 3000. Try:
76+
77+
http://localhost:3000/users/123
78+
79+
or
80+
81+
http://localhost:3000/users
82+
`)
83+
)

0 commit comments

Comments
 (0)