Development cd Node_js_Express_MongoDB
➜ Node_js_Express_MongoDB ls
➜ Node_js_Express_MongoDB express -c stylus
OR
express -c stylus YOUR_APP
create : .
create : ./package.json
create : ./app.js
create : ./public
create : ./public/javascripts
create : ./public/images
create : ./public/stylesheets
create : ./public/stylesheets/style.styl
create : ./routes
create : ./routes/index.js
create : ./routes/user.js
create : ./views
create : ./views/layout.jade
create : ./views/index.jade
install dependencies:
$ cd . && npm install
run the app:
$ node app
➜ Node_js_Express_MongoDB npm install -d
jade@0.31.1 node_modules/jade
├── character-parser@1.0.2
├── mkdirp@0.3.5
├── commander@1.1.1 (keypress@0.1.0)
├── with@1.0.4 (lexical-scope@0.0.12)
├── monocle@0.1.48 (readdirp@0.2.4)
└── transformers@2.0.1 (promise@2.0.0, css@1.0.8, uglify-js@2.2.5)
Check id mondgo is running
http://www.mkyong.com/mongodb/how-to-install-mongodb-on-mac-os-x/
Or install it here
http://www.mkyong.com/mongodb/how-to-install-mongodb-on-mac-os-x/
Node_js_Express_MongoDB ps -ef | grep mongo
0 62 1 0 11May13 ?? 67:51.38 /usr/local/mongodb/bin/mongod run --config /usr/local/mongodb/mongod.conf
0 74879 1 0 7:21am ?? 0:04.45 /usr/local/mongodb/bin/mongod
501 75707 63231 0 7:36am ttys000 0:00.00 grep mongo
run the app
node app.js
Express
Welcome to Express
:)
require mongo
in package.json
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.2.5",
"jade": "*",
"stylus": "*",
"mongodb": ">= 0.9.6-7"
}
}
package.json is like GEM file in rails
UPDATE
Install nodemon
Nodemon will reload your application each time it changes so you don't need to restart it.
npm install -g nodemon
http://blog.ijasoneverett.com/2013/03/a-sample-app-with-node-js-express-and-mongodb-part-1/
http://expressjs.com/guide.html
UPDATE:
update the package.json because heroku need a version
{
"name": "application-name",
"version": "0.0.1",
"engines": {
"node": "0.10.x",
"npm": "1.2.x"
},
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.2.5",
"jade": "*",
"stylus": "*",
"mongodb": ">= 0.9.6-7"
}
}
Push it on heroku
➜ Node_js_Express_MongoDB git:(master) ✗ heroku create
Creating nameless-sea-6255... done, stack is cedar
http://nameless-sea-6255.herokuapp.com/ | git@heroku.com:nameless-sea-6255.git
Git remote heroku added
➜ Node_js_Express_MongoDB git:(master) ✗ git push heroku
add mongo to heroku
heroku addons:add mongolab
➜ Node_js_Express_MongoDB git:(master) heroku addons:add mongolab
----> Adding mongolab to nameless-sea-6255... done, v6 (free)
Welcome to MongoLab. Your new database is ready for use. Please consult the MongoLab Add-on Admin UI for more information and useful management t
Create a Procfile
and add
web: node app.js
this tells heroku what to run when it deployed
➜ Node_js_Express_MongoDB git:(master) heroku ps
Process State Command
-------- --------- -------
run.9003 up for 9m node
➜ Node_js_Express_MongoDB git:(master) heroku ps:scale web=1
Scaling web processes... done, now running 1
➜ Node_js_Express_MongoDB git:(master) heroku config:add NODE_ENV=production
Adding config vars and restarting app... done, v8
NODE_ENV => production
Change on app.js
var port = process.env.PORT || 3000;
app.listen(port);
https://devcenter.heroku.com/articles/nodejs-mongoose
Heroku connection string
https://github.com/p15martin/BlogMongoDbNativeDriver/blob/master/web.js
heroku config | grep MONGOLAB_URI
No comments:
Post a Comment