분류 전체보기(329)
-
express [ TIL ] [ node.js ]
Problem express 는 무엇인가 Try npm install express const express = require('express') const app = express() const port = 4001 app.get('/', (req, res) => { res.send('안녕 세상아'); }) app.listen(port, () => { console.log(`http://localhost:${port} 연결완료`) }) Solve - node.js 위에서 동작하는 웹 프레임워크 - node.js 개발 시 개발을 빠르고 손쉽게 도와주는 역할, 이는 미들웨어 구조 때문에 가능한 것이다. 자바스크립트 코드로 작성된 다양한 기능의 미들웨어는 개발자가 필요한 것만 선택하여 express 와 ..
2023.06.25 -
PM2 사용
node.js & mongoDB 를 우분투에서 계속 실행할 수 있는 방법에는 PM2 가 있다. node.js 를 실행하고 관리하도록 만들어진 pm2 를 이용한다. pm2 란 프로세스 매니징 도구로 node.js 를 편하게 관리할 수 있게 도와주는 라이브러리 이다. 대표적으로 터미널을 종료하더라도 웹 서버가 실행될 수 있게 하거나 로그 정보들을 실시간으로 확인한다. sudo -s npm install -g pm2 pm2 start app.js 프로젝트 종료하는 법 pm2 delete 0 pm2 list 를 입력했을 때 프로세스가 존재하지 않다면 성공적으로 종료된 것이다. pm2 재시작 pm2 restart app.js. # app.js를 재시작합니다. pm2 restart [idNumber] pm2 관리중..
2023.06.24 -
AWS EC2 배포하기
선행작업 https://muyeon95.tistory.com/186 github SSH Repository [ git ] - 우선 repository 를 생성한다. - SSH 키를 발급받는다. 생성한 repository 를 사용하기 위해서 로컬환경에서 깃허브를 사용하기 위해 인증을 받아야 한다. 첫째 Personal access token 을 등록하는 것 둘째 SSH muyeon95.tistory.com https://ap-northeast-2.console.aws.amazon.com/ec2/home?region=ap-northeast-2#Home: https://ap-northeast-2.console.aws.amazon.com/ec2/home?region=ap-northeast-2#Home: ap-n..
2023.06.24 -
github SSH Repository [ git ]
- 우선 repository 를 생성한다. - SSH 키를 발급받는다. 생성한 repository 를 사용하기 위해서 로컬환경에서 깃허브를 사용하기 위해 인증을 받아야 한다. 첫째 Personal access token 을 등록하는 것 둘째 SSH 를 등록하는 것 SSH 발급 ssh-keygen -t rsa -b 4096 -C "본인의이메일@gmail.com" - RSA 키를 등록할 때 위치를 지정하거나, 패스워드를 지정하지 않고 기본값으로 설정 키가 생성된 곳 : /Users/기기이름/.ssh 키 생성 확인 cat ./id_rsa cat ./id_rsa.pub 정상적으로 키를 발급 받았다면 개인키를 깃허브에 등록해야 한다. SSH Key 복사 cat ~/.ssh/id_rsa.pub 출력된 SSH Ke..
2023.06.24 -
params [ TIL ] [ node.js ]
Problem req.params 가 빈 객체가 전달된다. // index.js const express = require("express"); const commentRouter = require("./comments"); const postRouter = require("./posts"); const router = express.Router(); router.use("/posts", postRouter); router.use("/posts/:_postId", commentRouter) module.exports = router; // comments.js router.post("/comments", async (req, res) => { try { const postId = req.params; ..
2023.06.24 -
async / await [ TIL ] [ node.js ]
Problem express 를 이용하여 간단한 게시판 api 를 만들던중 undefined 가 발생했다. Try router.post("/", async (req, res) => { console.log(req.body); try { const { title, content, userId } = postCreateValidation.validateAsync( req.body ); console.log(title, content, userId); const post = await Post.create({ title, content, userId, }); res.json(post); } catch (err) { if (err.isJoi) { return res.status(422).json({ messa..
2023.06.22