-
node.js 서버구동 세팅,방법카테고리 없음 2022. 1. 27. 10:38
22 리눅스 + 서버구동 NVM설치
cd ~ ls -al //nvm 폴더가 있는지 확인하기 vi bashrc source ~/.bashrc nvm --version nvm install --lts node -v //버전 확인
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
> 화살표
```repl
npm
express 라이브러리 npm update npm init //enter 난사 output package.json npm install express
서버구동
통합 터미널에 wsl 입력 후
localhost:3000const express = require("express") //node_module에 있는 express 폴더안에있는 코드 가져오기 const app = express() app.get('/',(req,res)=>{ res.send(`<div style="color:red;>asdfsds</div>`) }) //console.log(app) dataType 이 객체구나 //get()-> 요청이 들어오는데 // 첫번째 인자값의 역활 URI (PATH) -> HOST // / 하나는 host 하나만 말한다 // 두번째 인자값 CB(콜백) 함수를 넣는다 // 콜백 함수에도 인자값이 2개가 존재함 // 요청,응답 app.get('/',(요청,응답)=>{ 응답.send("<h1>hello express</h1>") }) //http://localhost:3000/node app.get('/node',(요청,응답)=>{ 응답.send("<h2>hello,node</h2>") }) app.listen(3000,()=>{ console.log('웹서버 온!') }) //express 실행 // localhost:3000 = // localhost:3000 == // localhost:3000/hello == /hello //node server // 브라우저를 킨 후 http://localhost:3000 입력