public todolist = async (req: express.Request, res: express.Response) => {
    let result: CommunicationResult = new CommunicationResult();

    try {
        const param_date: any = req.query.date;

        let query: any = {};
        if(param_date != null) {
            const start: Date = new Date(param_date + " 00:00:00");
            const end: Date = new Date(param_date + " 23:59:59");

            query["date"] = {
              $gte: start,
              $lte: end
            };
            
        }
        else {
          result.set(CommunicationCode.FAIL_EMPTY_PARAMETER);
          result.msg = "파라미터를 검출하지 못했습니다.";
          throw result;
        }

        console.log("query : ", query);
        
        // SQL의 Select로 본다.
        // find : query로 검색된 결과를 보여준다. (return array)
        const todo: TodoModel = await this.db.findOne(this.TODO_DB_ID, query);
        if(todo == undefined) {
          result.set(CommunicationCode.DB_FAIL_NO_DATA);
          result.msg = "데이터가 없음.";
          throw result;
        }

        let searchQuery: any = {};
        searchQuery["date"] = {
          $gte: ( req.query.start != undefined) ? moment(req.query.start).toDate() : moment("1970-01-01").toDate(),
          $lte: (req.query.end != undefined) ? moment(req.query.end).toDate() : moment("2999-12-31").toDate()
        };
        
        const remainderList: ReMmindersInnerModel[] = await this.db.find(this.REMINDER_DB_ID, searchQuery);

        res.send({ _COM: result, data: {
          date: todo.date,
          todo: todo,
          remainder: remainderList
        }});

        
    } catch (e) {
        if (e instanceof CommunicationResult) {
            result = e;
            Common.log(LogType.error, `[/api/todo/todolist], try ~ catch : ${e.msg}`);
        } else {
            result.set(CommunicationCode.FAIL_UNKNOWN);
            result.msg = e.message;
            Common.log(LogType.sev_error, `[/api/todo/todolist], try ~ catch : ${e}`);
        }
        res.send({ _COM: result });
    }
  }

간단하게 SELECT 하는 코드를 만들어보았다

DB- MongoDB 

NodeJS 

NoSQL 쿼리는 정말 편한 것 같다~ 앞으로 crud 도 만들 예정이다

'Node.js' 카테고리의 다른 글

Express ?  (0) 2019.09.03
Nodejs CRUD API 만들어보기 ( 초급 )  (0) 2019.08.29
REST – PUT vs POST  (0) 2019.08.28
Node.js로 hello world 출력해보기  (0) 2019.08.07
노드 JS 설치해보기  (0) 2019.07.30

먼저 폴더를 만듭니다 

myapp 이라는 폴더를 자신이 편한 경로에 만들어줍니다.

그다음 V

SC를 켜고 Ctrl + ` 를 눌러 터미널을 킨 뒤 

npm init => 패키지 생성

npm install =>   npm 실행

명령어를 입력해줍니다

노란줄의 index.js 파일이 Default값으로 들어가고 package.json 파일이 만들어집니다. 

그럼이제 express를 install 해보겠습니다.

npm install express --save 를 입력합니다.

 

그러면 package-lock.json 이 생성됨을 볼 수 있습니다.

package-lock.json 에 들어가보면

express가 정상 설치됨을 알 수 있습니다.

 

그러면 index.js에 코딩을 해보겠습니다.

이렇게 코딩을 해주고 터미널에서 node index.js  를 실행해줍니다.

그러면 

열림이라는 문구와 http://localhost:3000/ 번 포트로 접속이 가능합니다. 

그럼 http://localhost:3000/ 로 접속을 해볼까요?

 

정상적으로 Hello World! 가 찍힌 것을 볼 수 있습니다!

 

감사합니다 :)

'Node.js' 카테고리의 다른 글

Express ?  (0) 2019.09.03
Nodejs CRUD API 만들어보기 ( 초급 )  (0) 2019.08.29
REST – PUT vs POST  (0) 2019.08.28
간단한 Todolist Select API를 만들어보았다!  (0) 2019.08.26
노드 JS 설치해보기  (0) 2019.07.30

https://nodejs.org/en/ 에 들어가서 설치를 합니다.

 

좌측에 있는 10.16.0 LTS를 설치합니다.

 

이러한 화면이 뜨는데 Next 를 계속 눌러줍니다. 만약에 설치가 되어있다면

 

 

 

이러한 화면이 뜹니다.

 

이렇게 설치를 한다면 윈도우를 누른다음 cmd 라는 명령어를 입력합니다.

 

명령어 node -v 로 버전이 잘 나오는 지 확인하면 끝입니다~~~

'Node.js' 카테고리의 다른 글

Express ?  (0) 2019.09.03
Nodejs CRUD API 만들어보기 ( 초급 )  (0) 2019.08.29
REST – PUT vs POST  (0) 2019.08.28
간단한 Todolist Select API를 만들어보았다!  (0) 2019.08.26
Node.js로 hello world 출력해보기  (0) 2019.08.07

+ Recent posts