[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的主要内容,如果未能解决你的问题,请参考以下文章

同时运行 Node.js server 和 yarn serve vue-cli app

我无法在终端中运行 ng serve 命令

弃用警告:配置选项`config.serve_static_assets`已重命名为`config.serve_static_files`

由于没有从 express-serve-static-core 导出 ParsedQ,构建失败

Node.js web快速入门 -- KoaHub.js组件koa-static-server

Vue-cli3执行serve和build命令时nodejs 内存溢出问题