728x90 반응형 Node.js2 path 메서드로 경로와 파일 보내기 path 메서드로 경로와 파일 보내기 /// web.js const express = require("express"); const path = require("path"); // 주소관련 메서드 const nodeserver = express(); const port = process.env.PORT || 8003; /// 서버에서 쓰는 중요 키워드2개. 보안상의 이유로 이렇게 사용한다. // __dirname : 디렉토리이름, __filename : 파일이름 nodeserver.use(express.static(path.join(__dirname, './html'))) // html 폴더 사용. nodeserver.get("/", (req, res) => { res.sendFile(path.join(.. 2024. 1. 17. web.js 작성하기 3. web.js 작성 web.js 작성 서버 끌때 : node - Ctrl + C - 확인 서버끄고 npm run server로 다시 실행해야 확인가능 web.js // 앞에 경로없으면 모듈 데려옴. 경로있으면 파일 데려옴. const express = require("express"); // require : 원래 js method const app = express(); /* 유일하게 entry point만 이렇게express()를 정의할 수 있음! 연결할 서버는 하나이기때문. 즉, 카페24에선 web.js에서 한번만 정의하기. */ /// 위에 2줄을 이렇게 한줄로 쓸 수도 있다. 알아만 두기. // const express = require("express")(); app.get("/", (re.. 2024. 1. 17. 이전 1 다음 728x90 반응형