Node js/생활 코딩 Node js
express-정적파일 서비스하는 법
shinwoong_BE
2019. 2. 7. 22:37
- 1app.use(express.static('read할 폴더'));
cs
- read할 정적 폴더 이름을 static 괄호 안에 작성한다. 웹 페이지에 이미지를 넣고 싶다면
123app.get('/route', function(req, res) {res.send('Hello Router, <img src="/route.jpg">' );})cs
위와 같이 작성하여 이미지를 추가시키면 된다.
주소가 localhost:3000/route 로 사용자가 접속하였을 때 Hello Router라는 문자열을 화면에 표시하고, 화면에 route.jpg 이미지를 적용시키겠다는 의미이다.