Expressjs에서 static file 사용하기
간단히 말하면 Spring에서 resource의 폴더와 같은 역활을 하는 것을 express.js에서 사용하는 방법이다.
- Path to
public /images /css /js /html
- 기본적인 방법
Source code
app.use(express.static('public'));
Load the files under the public directory
http://localhost:3000/images/kitten.jpg http://localhost:3000/css/style.css http://localhost:3000/js/app.js http://localhost:3000/images/bg.png http://localhost:3000/hello.html
- 두가지 폴더를 지정할때
Source code
app.use(express.static('public')); app.use(express.static('files'));
- Prefix path를 사용하는 방법
Source code
app.use('/static', express.static('public'));
Load the files under the public directory, from the path prefix “/static”
http://localhost:3000/static/images/kitten.jpg http://localhost:3000/static/css/style.css http://localhost:3000/static/js/app.js http://localhost:3000/static/images/bg.png http://localhost:3000/static/hello.html
관련 링크 : http://expressjs.com/starter/static-files.html











