📗TIL/Node.js
-
Node express로 서버열고 express-ejs-layouts 사용하기📗TIL/Node.js 2022. 5. 15. 16:03
0. 파일을 폴더에 정리 제작한 사이트를 폴더별로 정리합니다. (서버를 구성할 js파일 모듈화) bin 폴더 : 서버를 열어줄 www.js파일을 넣어줍니다. public 폴더 : 웹사이트에 사용된 css img js를 폴더별로 구분하여 넣어줍니다. routes 폴더 : 웹사이트 내 모든 경로를 지정해주는 route.js 파일을 넣어줍니다. views 폴더 : 웹사이트에 들어갈 모든 html(express-ejs-layouts 사용할 경우 ejs)파일을 넣어줍니다. app.js 파일 : app.js는 파일로 넣어줍니다. 1. node express를 이용하여 서버 실행 route.js(라우터)를 모듈로 작성해 라우터 모듈에 미들웨어 함수를 로드하고 app.js로 라우터 모듈을 마운트 하여 사용 - app...
-
node.js 로 웹서버 만들기 (+ node express)📗TIL/Node.js 2022. 5. 8. 22:11
node.js로 서버 만들기 const http = require('http'); const hostname = '127.0.0.1'; const port = 3000; const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.write('node start1'); res.end('node start2'); }); server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); }); node.js로 서버 만들기 const http = ..