You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are basically two parts to this demo - two servers - within one file, server.js, which may sound a little confusing but the two servers do different things.
13
+
14
+
The first server, httpServer, serves up static html/js/css to the browser and the second, mongodbServer, is purely for saving and retrieving data from the mongodb.
8
15
9
16
I've put both servers in the server.js which makes it extremely long and challenging to maintain but it does the job for this demo. Also, each server is listening on its own port. If you are only allowed access to one public port, you could choose one server to listen on that port then pass the events to the other server which may be interested in different routes. For instance, in this case, if the http server listens for a /messages route, it could trigger an event and pass that to the mongo server.
10
17
11
-
In addition to server.js, I've also refactored it into two separate files: server-http.js and server-mongo.js.
18
+
In addition to server.js, I've also refactored it into two separate files: server-http.js and server-mongo.js.
19
+
20
+
If you only need the mongobd server, you might start with the server-mongo folder.
12
21
13
22
## HTTP SERVER
14
23
15
-
Originally, this tutorial started out as purely a mongodb one but I wanted to see the data in a browser and since this is a collection of Backbone tutorials, I might as well include some client-side backbone views. I aslo started working on it before discovering Google's Yeoman which includes its own web server that serves static files thus making the HTTP portion not necessary when testing locally, however, when you move to host these files somewhere else like nodejitsu, you may need to use your own static web server if it doesn't support nginx or apache.
24
+
Originally, this tutorial started out as purely a mongodb one but I wanted to see the data in a browser and since this is a collection of Backbone tutorials, I might as well include some client-side backbone views. I aslo started working on it before discovering Google's Yeoman which includes its own web server that serves static files thus making the HTTP portion not necessary when testing locally, however, when you move to host these files somewhere else like nodejitsu, you may need to use your own static web server if it doesn't support nginx or apache.
25
+
26
+
But before using Yeoman, you might want to try open a terminal to the directory of this app and typing:
16
27
17
-
To view the data in your browser, you will need to host the app locally. In my case, I started up Yeoman using the terminal.
28
+
$ node server
29
+
30
+
Next, you will need to open browser and point it to:
31
+
32
+
http://localhost:8080/
33
+
34
+
Alternatively, you can use Yeoman which would automatically launch a browswer window and also you more features like live reload.
18
35
19
36
$ yeoman server
20
37
@@ -24,9 +41,8 @@ Yeoman automatically launches a browser window to:
24
41
25
42
http://localhost:3501/
26
43
27
-
You can also see this same view by visiting the redundant http server:
44
+
http server:
28
45
29
-
http://localhost:8080/
30
46
31
47
If you'd like to see the raw messages as a json dump, you can point your browser to:
Copy file name to clipboardExpand all lines: examples/nodejs-mongodb-mongoose-restify/server-mongo/README.md
-5Lines changed: 0 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,6 @@
2
2
3
3
In order to persist data to a mongodb database, a server is created to handle all the CRUD operations.
4
4
5
-
This demo attempts to answer two burning questions:
6
-
7
-
1. how do I setup a local server to test mongodb?
8
-
2. how do I deploy this server to the internet and use it to store date for my other projects?
9
-
10
5
## LOCAL
11
6
12
7
The quickest way to learn mongodb is by installing it on your local machine using a service like brew or mac ports. For instance, to install mongodb using brew open a terminal window:
0 commit comments