[Node.js] Serve Static Files with Express

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Node.js] Serve Static Files with Express相关的知识,希望对你有一定的参考价值。

In this lesson we will find out how to serve static assets (images, css, stylesheets, etc.) with Express. We will go over writing initial boilerplate for a simple Express app, and using Express‘s built-in middleware to serve these assets through a web server on Node.js.

 

const path = require(‘path‘);
const express = require(‘express‘);
const app = express();

app.use(‘/images‘, express.static(path.join(__dirname, ‘public/images‘)));

app.listen(8080);

 

以上是关于[Node.js] Serve Static Files with Express的主要内容,如果未能解决你的问题,请参考以下文章