본문 바로가기
WEB/Nodejs-express

[Nodejs-express] 정적인 파일 사용하기

by Ellen571 2020. 8. 9.

[생활코딩] 정적인 파일의 서비스

 

 

app.use(express.static('public'));
// public 디렉토리 안에서 static 파일을 찾겠다는 코드

 

public/images 폴더 안에 img01.jpg라는 파일이 있다면

http://localhost:3000/images/img01.jpg

로 접속시 이미지가 나옴

 

 

본문에서 사용하기

 

app.get('/', function(req, res){
  var title = 'Welcome';
  var description = 'Hello, Node.js';
  var list = template.list(req.list);
  var html = template.HTML(title, list,
    `<h2>${title}</h2>${description}
     <img src="/images/img01.jpeg">
    `,
    `<a href="/create">create</a>`
  );
  res.send(html);
});
반응형