Web dev/NodeJS
-
NodeJS / dotenv 로 환경변수 설정하기Web dev/NodeJS 2022. 3. 27. 11:35
mysql로 AWS RDS 연결에 성공하였다. 파일그대로 깃헙에 업로드하면 DB계정정보가 유출되니까 환경변수에 설정하여 업로드 해준다. .env 파일은 .gitignore에 설정해줘야 한다. .gitignore에 설정하면 업로드 할 때 설정파일은 업로드 되지 않는다. // .gitignore .DS_Store .env .env.local .env.development.local .env.test.local .env.production.local 이런식으로 해주면 된다. 1. dotenv 설치 npm i dotenv 2. .env 설정 // .env 파일 파일명앞에 '.' 을찍어줘야함 PORT = 5000 DB_HOST = "호스트 정보" DB_USER = "아이디" DB_PSWORD = "비밀번호" DB..
-
NodeJS / http 내장모듈로 로컬서버 띄우기Web dev/NodeJS 2022. 2. 17. 21:33
1. http 내장모듈을 require하고 createServer 매서드로 app변수를 만들고. 2.app.listen(포트번호,콜백함수); 3.라우팅 설정 if문을 사용해 라우팅설정을 해준다. createServer 매서드는 req,res를 인자로 받을 수 있다. 4. 상당히 지저분해지므로 express를 사용하면 된다. 출처 : https://www.youtube.com/channel/UCS0F25vig_sPIQXMiK8IdSg
-
NodeJS / express 서버 띄우기Web dev/NodeJS 2022. 2. 17. 21:18
1. node.js 공홈에서 다운로드 한 뒤 작업할 디렉토리를 만들어준다. 2.익스프레스를 설치해준다. (-s 는 --save 라는 표현으로 package-lock.json파일과 node_modules 폴더가 생성된다.) npm i express -s 3.app.js 파일을 만들고 express 를 require 해서 app 변수에 넣고 app.listen(포트숫자, 콜백함수) 4.노드를 실행시켜 로컬서버가 실행됐는지 확인 node app.js 이렇게 떴다면 성공! 서버가 안띄어져 있으면 표시할 수 없음으로 뜬다. 코드가 수정되면 서버를 껐다 켜야하는데 nodemon 을 사용하면 껐다켰다 안해도 된다. npm i nodemon -s 노드몬 실행방법 nodemon node 실행파일경로 package.jso..