

To confirm it, load a picture in public directory. Now root route will be set to public directory for static files. use middleware to serve static filesĪpp.use('/static', express.static('public')) To add virtual path, you can update the code as below. The above code can also be used to create a virtual path along with setting public directory for project. To do this, first of all we will create a folder or directory named public in our project directory then add the following line of code in our index.js. However, if we have to serve static files, we will have to enable middleware dedicated for this purpose. Static files are downloaded by clients from server. Express JS does not allow to serve static files likes images, videos etc. It is non-intuitive and very complex way.įor details and examples please see the pug-plugin site.Ĭonst path = require ( 'path' ) const PugPlugin = require ( 'pug-plugin' ) module.
