내맘대로 살기🎉

[Node.js] OrientDB를 적용시키자. 본문

개발자의 길/Node.js

[Node.js] OrientDB를 적용시키자.

해림😶 2017. 5. 13. 00:24


DB를 구축할 때 대부분이 이런 형식을 따른다.


1
2
3
4
5
6
7
8
9
10
11
get('topic/') : view.jade
get('topic/:id') : view.jade
get('topic/add') : add.jade
    post('topic/add')
    get('topic/:id')
get('topic/:id/edit') : edit.jade
    post('topic/:id/edit')
    get('topic/:id')
get('topic/:id/delete') : delete.jade
    post('topic/:id/delete')
    get('topic/')


node.js에 OrientDB적용시키기


1
2
3
4
5
6
7
var OrientDB = require('orientjs');
var server = OrientDB({
    host : 'localhost',
    port : 2424,
    username : 'root',
    password : '' // 실제로는 비밀번호를 다른 파일에 저장한다. (보안을 위햬)
});

이 코드를 js파일에 넣어줘야 orientDB를 적용시킨다고 알려주는 것이다. 

그리고 var db = server.use('studynodejs'); 이 코드도 함께 적용해야한다. studynodejs는 DB의 이름이다.

tip) jade에서 - 뒤에는 javascript를 사용한다. 그리고 url을 조금 숨기고 싶다면, encodeURIComponent()라는 메소드로 변경 가능




Comments