728x90

출처 : 인프런_따라하며 배우는 노드, 리액트 시리즈 — 기본 강의

Step 1) Node js 다운로드

nodejs.org/ko/

 

Node.js

Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.

nodejs.org

 

 

에서 Node js 를 다운로드한다.

버전을 출력해서 설치가 완료된 것을 확인할 수 있다.

 

 

 

 

Step 2) npm package 만들기

$ npm init

Text Editior 에서 패키지를 확인해보자. 필자는 Visual Studio Code 를 사용해서 확인해보았다.

 

 

Step 3) Express js 다운로드

Express js 는 Node js를 위한 빠르고 개방적인 간결한 웹 프레임워크이다. 터미널에서 아래의 명령으로 다운로드한다.

$ npm install express --save

 

 

Step 4) index.js에서 기본적인 express 앱 만들기

index.js 는 백엔드의 시작점이다.

expressjs.com/en/starter/hello-world.html

 

Express "Hello World" example

Hello world example Embedded below is essentially the simplest Express app you can create. It is a single file app — not what you’d get if you use the Express generator, which creates the scaffolding for a full app with numerous JavaScript files, Jade

expressjs.com

위의 링크에서 텍스트를 복사하여 아래와 같이 입력한다.

아래와 같이 line 7 도 추가해준다.

저장 후 아래의 명령어를 실행함으로써 노드앱을 실행한다. (시작점은 index.js)

$ npm start run

실행 확인 완료

 

 

 

Step 5) Mongo DB 연결

www.mongodb.com/1

 

The most popular database for modern apps

We're the creators of MongoDB, the most popular database for modern apps, and MongoDB Atlas, the global cloud database on AWS, Azure, and GCP. Easily organize, use, and enrich data — in real time, anywhere.

www.mongodb.com

가입 후 Project 생성 후 Cluster 를 만든다.

5–7분 기다리면 클러스터가 생성된다.

 

 

이제 저를 생성해보자.

connect 버튼을 클릭한 후 username, pw 를 입력하고 다음으로 넘어가서 connect with application을 클릭한다.

이때 connection string 을 copy 해놓는다.

 

 

 

 

Step 6) Moongoose 설치

Mongoose : MongoDB를 편하게 쓸 수 있는 Object Modeling Tool이다.

$ npm install mongoose -save

Mongoose를 이용해서 application과 MongoDB를 연결해보자.

line 6–9를 추가해준다. password는 아까 자신이 설정한 것으로 교체한다.

line 7은 아까 copy 한 connection string 이다.

MongoDB가 연결된 것을 확인할 수 있다.

728x90

+ Recent posts