본문 바로가기

데일리 공부 기록

Node.js 기초 설치 , 서버 생성, get 까지해보기

728x90

개요

1. Node 설치

2. Node npm을 이용한 express(라이브러리 가져오는 툴?) 설치하기

3. 서버 설치 후 GetMapping 2개 만들기

 


[1. Node 설치]

구글에서 node 검색 후 사이트에서 왼쪽 버튼 클릭하여 다운


[2. npm을 이용해 express 설치하기]

2-1) vsCode를 설치하여 터미널에 들어가기

2-2) npm init (npm이라는 라이브러리 설치를 도와주는 녀석을 가져오기)

2-3) npm install express(express라는 라이브러리 설치하기)

 엔터를 쭉 누르다가 "end point"가 나오면 파일명이 될 이름을 삽입 후 다시 엔터를 쭉 누르기


[3. 서버설치하기]

3-1) 

const express = require('express');
const app = express();
app.listen(8080, function(){
	console.log('포트 8080에 서버 오픈');
});
app.get('/pet', function(req,resp){
	resp.send('펫 용품 구매 사이트 경로');
});

app.get('/beauty', function(req,resp){
	resp.send('뷰티 용품 구매 사이트 경로');
});