this command will start mongoDB server
./mongod
basic port is 27017 and will create and use /data/db directory to save data
Sunday, September 14, 2014
MongoDB Basic command
I studied mongoDB
and This mongoDB structure is like json structure
and this has collection.
this is just start time ~ I don't know how deeply i shoud study this mongoDB
but I'm just curious about using it and be interested in getting information of this database
blow post is what i got from O'Reilly - MongoDB- The Definition Guide
34/216page
./mongodb
switch database
> use footer
show which db i use
> db
CRUD
create, read, update, delete
javascript functions are available in mongoDB
make post data
> post = {"title":"good",
... "content":"this is body",
... "date" : new Date()}
{
"title" : "good",
"content" : "this is body",
"date" : ISODate("2014-09-15T00:18:45.482Z")
}
and
i gonna insert this post to blog
>db.blog.insert(post)
find
> db.blog.find() or db.blog.findOne()
update
> post.comments = []
> db.blog.update({title:"good"}, post)
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
delete
> db.blog.remove({title:"good"})
show dbs = show databasenames
show collections = show collections in current database
show users = show users in current database
use <db name> = set current database to <db name>
db.help()
dob.foo.help()
Thursday, September 11, 2014
angularjs How to use Custom Select
what i just tell you is this is just one of many example and
I used it
so this is one way, not a solution of using it
<div class="sel_area" style="width:40%;">
<button class="btn_sel" type="button" ng-click='showDropdown()'>
{{selectedCondition.name}}
</button><span class="caret"></span>
<select id='searchCondition' ng-model='selectedCondition'
ng-options="condition.name for condition in conditions"
style='opacity: 0; width:0px; float:left;' >
<option value='이름'>이름</option>
<option value='전화번호'>전화번호</option>
<option value='id'>id</option>
</select></div>
$scope.conditions = [
{name:'이름', shade:'light'},
{name:'전화번호', shade:'dark'},
{name:'아이디', shade:'dark'}
];
$scope.selectedCondition = $scope.conditions[0];
$scope.showDropdown = function () {
var event;
var element = document.getElementById('searchCondition');
event = document.createEvent('MouseEvents');
event.initMouseEvent('mousedown', true, true, window);
element.dispatchEvent(event);
};
Monday, September 1, 2014
read json file and return json file in nodejs
1. at first reading json file
2. json string to object
3. return json
var express = require('express');
var router = express.Router();
var fs = require('fs');
/* GET users listing. */
router.get('/', function(req, res) {
var text= fs.readFile('./package.json', 'utf-8', function(err, data){
res.json(JSON.parse(data));
});
});
module.exports = router;
---------- package.json --------
{
"name": "myapp",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"express": "~4.8.6",
"body-parser": "~1.6.6",
"cookie-parser": "~1.3.2",
"morgan": "~1.2.3",
"serve-favicon": "~2.0.1",
"debug": "~1.0.4",
"jade": "~1.5.0",
"stylus": "0.42.3"
}
}
2. json string to object
3. return json
var express = require('express');
var router = express.Router();
var fs = require('fs');
/* GET users listing. */
router.get('/', function(req, res) {
var text= fs.readFile('./package.json', 'utf-8', function(err, data){
res.json(JSON.parse(data));
});
});
module.exports = router;
---------- package.json --------
{
"name": "myapp",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"express": "~4.8.6",
"body-parser": "~1.6.6",
"cookie-parser": "~1.3.2",
"morgan": "~1.2.3",
"serve-favicon": "~2.0.1",
"debug": "~1.0.4",
"jade": "~1.5.0",
"stylus": "0.42.3"
}
}
use express router and get & post parameters
This article is about make different methods called 'get', 'post'
and all is include all method
and also tell you the way getting paramter ~
I tested all~
var express = require('express');
var router = express.Router();
var fs = require('fs');
/* GET users listing. */
router.get('/', function(req, res) {
var param1 = req.param('param1');
console.log(param1);
var param2 = req.param('param2');
console.log(param2);
res.send();
});
router.post('/', function(req, res){
var param1 = req.param('param1');
console.log(param1);
var param2 = req.param('param2');
console.log(param2);
res.send();
});
router.all('/all', function(req, res){
console.log('all');
var param1 = req.param('param1');
console.log(param1);
var param2 = req.param('param2');
console.log(param2);
res.send();
});
module.exports = router;
and all is include all method
and also tell you the way getting paramter ~
I tested all~
var express = require('express');
var router = express.Router();
var fs = require('fs');
/* GET users listing. */
router.get('/', function(req, res) {
var param1 = req.param('param1');
console.log(param1);
var param2 = req.param('param2');
console.log(param2);
res.send();
});
router.post('/', function(req, res){
var param1 = req.param('param1');
console.log(param1);
var param2 = req.param('param2');
console.log(param2);
res.send();
});
router.all('/all', function(req, res){
console.log('all');
var param1 = req.param('param1');
console.log(param1);
var param2 = req.param('param2');
console.log(param2);
res.send();
});
module.exports = router;
Friday, August 29, 2014
Simple Restful Api (get) without db Connection ( Node Js + Express)
This sample will show you that how simple nodejs http restful API is working
first test is returning array json data
second and Third is just restun json data
======== sample source ===========
var express = require('express');
var app = express();
app.get('/school', function(req,res){
res.send([{bus:'bus1'}, {bus:'bus2'}]);
});
app.get('/school/:number', function(req, res){
res.send({id:'two path', number:req.params.number});
});
app.get('/school/:number/:destination', function(req, res){
res.send({id:'three path', destination:req.params.destination});
})
app.listen(3000);
console.log('Listen on port 3000......');
and result list
1. http://192.168.123.165:3000/school
2. http://192.168.123.165:3000/school/second
{
"id": "two path",
"number": "second"
}
3. http://192.168.123.165:3000/school/third
{
"id": "three path",
"destination": "third"
}
first test is returning array json data
second and Third is just restun json data
======== sample source ===========
var express = require('express');
var app = express();
app.get('/school', function(req,res){
res.send([{bus:'bus1'}, {bus:'bus2'}]);
});
app.get('/school/:number', function(req, res){
res.send({id:'two path', number:req.params.number});
});
app.get('/school/:number/:destination', function(req, res){
res.send({id:'three path', destination:req.params.destination});
})
app.listen(3000);
console.log('Listen on port 3000......');
and result list
1. http://192.168.123.165:3000/school
[
{
"bus": "bus1"
},
{
"bus": "bus2"
}
]
{
"bus": "bus1"
},
{
"bus": "bus2"
}
]
2. http://192.168.123.165:3000/school/second
{
"id": "two path",
"number": "second"
}
3. http://192.168.123.165:3000/school/third
{
"id": "three path",
"destination": "third"
}
webstorm and node js setup
in webstorm you can use nodejs easily
1. file -> setting -> javascript -> library ->
and Node.js check
2. file -> setting -> Node.js and NPM and install packages
1. file -> setting -> javascript -> library ->
and Node.js check
2. file -> setting -> Node.js and NPM and install packages
Subscribe to:
Posts (Atom)