Skip to content

Commit 0e0dbc4

Browse files
committed
first working code
1 parent 9d79c71 commit 0e0dbc4

File tree

4 files changed

+41
-50
lines changed

4 files changed

+41
-50
lines changed

README.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Modern Web Application using MEAN stack
22

3-
This is a basic boilerplate for the MEAN stack ([MongoDB](https://www.mongodb.org/), [Express](http://expressjs.com/), [AngularJS](https://angularjs.org/) and [Node.js](https://nodejs.org)) on [IBM Cloud](http://bluemix.net).
3+
This is a basic boilerplate for the MEAN stack ([MongoDB](https://www.mongodb.org/), [Express](http://expressjs.com/), [AngularJS](https://angularjs.org/) and [Node.js](https://nodejs.org)) on [IBM Cloud](https://cloud.ibm.com).
44

5-
This application uses the [Compose for MongoDB service](https://console.bluemix.net/catalog/services/compose-for-mongodb) and [Node.js runtime](https://www.ng.bluemix.net/docs/starters/nodejs/index.html) on IBM Cloud.
5+
This application uses the [IBM Cloud Databases for MongoDB service](https://cloud.ibm.com/catalog/services/databases-for-mongodb) and [Node.js runtime](https://cloud.ibm.com/docs/runtimes/nodejs?topic=Nodejs-nodejs_runtime) on IBM Cloud.
66

77
<img src="ReadME-Images/Architecture2.png">
88

@@ -12,13 +12,13 @@ This application uses the [Compose for MongoDB service](https://console.bluemix.
1212
- Authentication with username/password
1313
- Protected routes that can only be accessed by authenticated users
1414
- Bootstrap CSS framework & [Cosmo theme](https://bootswatch.com/cosmo/)
15-
- HTTPS built-in if deployed to [IBM Cloud](#deploy-to-bluemix)
15+
- HTTPS built-in if deployed to [IBM Cloud](#deploy-to-ibm-cloud)
1616
- [Mongoose](https://github.com/Automattic/mongoose) for MongoDB interactions.
1717
- [PassportJS](http://passportjs.org) for authentication, with over 300 authentication strategies to pick from.
1818

1919
## Application Requirements
2020
- [Node.js & NPM](https://nodejs.org/en/download/)
21-
- [Compose for MongoDB database](https://console.bluemix.net/catalog/compose-for-mongodb)
21+
- [IBM Cloud Databases for MongoDB](https://cloud.ibm.com/catalog/services/databases-for-mongodb)
2222
- [Cloud Foundry Command Line Tool](https://docs.cloudfoundry.org/devguide/installcf/)
2323

2424
## Getting Started
@@ -35,31 +35,30 @@ This application uses the [Compose for MongoDB service](https://console.bluemix.
3535

3636
Option 1 (launch this app directly from this repo):
3737

38-
[![Deploy to Bluemix](https://bluemix.net/deploy/button.png)](https://bluemix.net/deploy?repository=https://github.com/IBM-Bluemix/Nodejs-MEAN-Stack)
38+
[![Deploy to IBM Cloud](https://cloud.ibm.com/devops/setup/deploy/button.png)](https://cloud.ibm.com/devops/setup/deploy?repository=https://github.com/IBM-Cloud/nodejs-MEAN-stack)
3939

4040
Option 2 (deploy from your local machine):
4141

4242
1. Clone or download this repo onto your machine.
4343
2. Open a terminal prompt to the directory of your application.
44-
3. If you don't have an account, [create a free one here](https://console.ng.bluemix.net/registration/).
45-
4. Set your Cloud Foundry CLI tool's API endpoint to: `ibmcloud api https://api.ng.bluemix.net `
46-
5. Login to your account via the command line: `ibmcloud login`
47-
6. Target your account ORG and SPACE `ibmcloud target -o ORG -s SPACE`
48-
7. Create the instance of Compose for MongoDB on IBM Cloud: `ibmcloud cf create-service compose-for-mongodb Standard mean-starter-mongodb`
49-
8. Push your app to IBM Cloud with `ibmcloud cf push`
50-
9. Done, the app should be looking like:<img src="ReadME-Images/live-app.png">
44+
3. If you don't have an account, [create a free one here](https://cloud.ibm.com).
45+
4. Login to your account via the command line: `ibmcloud login`
46+
5. Target your account ORG and SPACE `ibmcloud target --cf`
47+
6. Create the instance of Compose for MongoDB on IBM Cloud: `ibmcloud cf create-service databases-for-mongodb standard mean-starter-mongodb`
48+
7. Push your app to IBM Cloud with `ibmcloud cf push`
49+
8. Done, the app should be looking like:<img src="ReadME-Images/live-app.png">
5150

5251

5352

5453
#### Problems or Questions?
5554

56-
Create a [GitHub issue](https://github.com/IBM-Bluemix/nodejs-MEAN-stack/issues/new) for questions or problems occurs using this demo.
55+
Create a [GitHub issue](https://github.com/IBM-Cloud/nodejs-MEAN-stack/issues/new) for questions or problems occurs using this demo.
5756

5857
## Critical Files & Folders
5958

6059
| File | Description |
6160
| ---------------------------------- | ------------------------------------------------------------ |
62-
| [**manifest.yml**](./manifest.yml) | File that defines deployment paramaters. [More info here](https://www.ng.bluemix.net/docs/manageapps/depapps.html#appmanifest)
61+
| [**manifest.yml**](./manifest.yml) | File that defines deployment paramaters. [More info here](http://docs.cloudfoundry.org/devguide/deploy-apps/manifest.html)
6362
| [**.env.example**](./.env.example) | Set custom [environment variables](https://en.wikipedia.org/wiki/Environment_variable) for your application. This is the proper way to store credentials and other sensitive values.
6463
| [**server.js**](./server.js) | Main server file that the Node.js runtime uses. It contains all the server logic.
6564
| [**/server**](./server) | Folder for files used by the Node.js server
@@ -92,7 +91,7 @@ If you are not sure what your application name is, use this command to print you
9291
$ ibmcloud cf apps
9392
```
9493

95-
For more detailed information on troubleshooting your application, see the [Troubleshooting section](https://www.ng.bluemix.net/docs/troubleshoot/tr.html) in the documentation.
94+
For more detailed information on troubleshooting your application, see the [Troubleshooting section](https://cloud.ibm.com/docs/cloud-foundry-public?topic=cloud-foundry-public-ts-cf-apps) in the documentation.
9695

9796
## License
98-
See [LICENSE.MD](https://github.com/IBM-Bluemix/Nodejs-MEAN-Stack/blob/master/LICENSE.md) for license information.
97+
See [LICENSE.MD](https://github.com/IBM-Cloud/nodejs-MEAN-stack/blob/master/LICENSE.md) for license information.

manifest.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
applications:
33
- name: mean-stack
4-
host: mean-${random-word}
4+
random-route: true
55
memory: 256M
66
services:
77
- mean-starter-mongodb
88
env:
99
NODE_ENV: cloud-foundry
1010
declared-services:
1111
mean-starter-mongodb:
12-
label: compose-for-mongodb
13-
plan: Standard
12+
label: databases-for-mongodb
13+
plan: standard

package.json

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"name": "mean-boilerplate-ibm-bluemix",
3-
"version": "1.0.0",
4-
"description": "MEAN (Mongo, Express, Angular, Node.js) Boilerplate for IBM Bluemix",
2+
"name": "mean-boilerplate-ibm-cloud",
3+
"version": "1.1.0",
4+
"description": "MEAN (Mongo, Express, Angular, Node.js) Boilerplate for IBM Cloud",
55
"main": "server.js",
6-
"engines" : { "node" : ">=4.4.5" },
6+
"engines" : { "node" : "6.*" },
77
"scripts": {
88
"start": "node server.js",
99
"dev": "nodemon server.js"
1010
},
1111
"repository": {
1212
"type": "git",
13-
"url": "https://github.com/IBM-Bluemix/Nodejs-MEAN-Stack.git"
13+
"url": "https://github.com/IBM-Cloud/nodejs-MEAN-stack.git"
1414
},
1515
"keywords": [
1616
"Node.js",
@@ -20,25 +20,24 @@
2020
"javascript",
2121
"boilerplate"
2222
],
23-
"author": "IBM Bluemix",
23+
"author": "IBM Cloud",
2424
"license": "Apache-2.0",
2525
"bugs": {
26-
"url": "https://github.com/IBM-Bluemix/Nodejs-MEAN-Stack/issues"
26+
"url": "https://github.com/IBM-Cloud/nodejs-MEAN-stack/issues"
2727
},
28-
"homepage": "https://github.com/IBM-Bluemix/Nodejs-MEAN-Stack",
28+
"homepage": "https://github.com/IBM-Cloud/nodejs-MEAN-stack",
2929
"dependencies": {
3030
"bcrypt": "^2.0.0",
3131
"body-parser": "^1.14.1",
32-
"cf-deployment-tracker-client": "0.0.8",
33-
"cfenv": "1.0.x",
34-
"connect-mongo": "^1.1.0",
32+
"cfenv": "^1.0.x",
33+
"connect-mongo": "^2.0.2",
3534
"cookie-parser": "^1.4.0",
36-
"dotenv": "^1.2.0",
37-
"express": "4.12.x",
35+
"dotenv": "^4.0.0",
36+
"express": "^4.15.x",
3837
"express-session": "^1.12.1",
3938
"express-validator": "^2.18.0",
40-
"mongoose": "^4.2.6",
41-
"passport": "^0.3.2",
39+
"mongoose": "^5.1.0",
40+
"passport": "^0.4.0",
4241
"passport-local": "^1.0.0"
4342
},
4443
"devDependencies": {}

server.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var express = require('express'),// server middleware
1313
expressValidator = require('express-validator'), // validation tool for processing user input
1414
cookieParser = require('cookie-parser'),
1515
session = require('express-session'),
16-
MongoStore = require('connect-mongo/es5')(session), // store sessions in MongoDB for persistence
16+
MongoStore = require('connect-mongo')(session), // store sessions in MongoDB for persistence
1717
bcrypt = require('bcrypt'), // middleware to encrypt/decrypt passwords
1818
sessionDB,
1919

@@ -40,20 +40,16 @@ if(appEnv.isLocal){
4040
sessionDB = process.env.LOCAL_MONGODB_URL;
4141
console.log('Your MongoDB is running at ' + process.env.LOCAL_MONGODB_URL);
4242
}
43-
// Connect to MongoDB Service on Bluemix
43+
// Connect to MongoDB Service on IBM Cloud
4444
else if(!appEnv.isLocal) {
4545
var mongoDbUrl, mongoDbOptions = {};
46-
var mongoDbCredentials = appEnv.services["compose-for-mongodb"][0].credentials;
47-
var ca = [new Buffer(mongoDbCredentials.ca_certificate_base64, 'base64')];
48-
mongoDbUrl = mongoDbCredentials.uri;
46+
var mongoDbCredentials = appEnv.services["databases-for-mongodb"][0].credentials.connection.mongodb;
47+
var ca = Buffer.from(mongoDbCredentials.certificate.certificate_base64, 'base64');
48+
mongoDbUrl = mongoDbCredentials.composed[0];
4949
mongoDbOptions = {
50-
mongos: {
51-
ssl: true,
52-
sslValidate: true,
53-
sslCA: ca,
50+
useNewUrlParser: true,
5451
poolSize: 1,
5552
reconnectTries: 1
56-
}
5753
};
5854

5955
console.log("Your MongoDB is running at ", mongoDbUrl);
@@ -72,7 +68,7 @@ Express Settings
7268
********************************/
7369
var app = express();
7470
app.enable('trust proxy');
75-
// Use SSL connection provided by Bluemix. No setup required besides redirecting all HTTP requests to HTTPS
71+
// Use SSL connection provided by IBM Cloud. No setup required besides redirecting all HTTP requests to HTTPS
7672
if (!appEnv.isLocal) {
7773
app.use(function (req, res, next) {
7874
if (req.secure) // returns true is protocol = https
@@ -89,10 +85,7 @@ app.use(cookieParser());
8985
app.use(session({
9086
secret: process.env.SESSION_SECRET || 'this_is_a_default_session_secret_in_case_one_is_not_defined',
9187
resave: true,
92-
store: new MongoStore({
93-
url: sessionDB,
94-
autoReconnect: true
95-
}),
88+
store: new MongoStore({ mongooseConnection: mongoose.connection }),
9689
saveUninitialized : false,
9790
cookie: { secure: true }
9891
}));
@@ -314,4 +307,4 @@ Ports
314307
********************************/
315308
app.listen(appEnv.port, appEnv.bind, function() {
316309
console.log("Node server running on " + appEnv.url);
317-
});
310+
});

0 commit comments

Comments
 (0)