【发布时间】:2019-09-07 04:56:27
【问题描述】:
我正在学习如何在 Node.js 服务器中发送 gzip 文件。
这是现在在我的服务器上运行的非常简单的代码:
var express = require('express');
var app = express();
var path = require("path");
app.use(express.static(__dirname + '/public'));
app.set('port', (process.env.PORT || 5000));
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.get('/', function(request, response) {
response.render('pages/index');
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
我的 gzip 文件是位于以下路径的文件夹中的 JavaScript 文件:
public/zipped/file.js.gz
我正在尝试使用npm i http-static-gzip-regexp、express-static-gzip 这两个 npm 插件之一,但我无法让它们工作。
- 第一个插件出现此错误
找不到模块“http-static-gzip-regexp”
我将它包含在以下代码中:
var staticGzip = require('http-static-gzip-regexp');
- 虽然我无法使用第二个插件使其工作,但这是我的代码:
var expressStaticGzip = require("express-static-gzip"); app.use("/", expressStaticGzip("/zipped"));
您有什么建议或建议让我了解如何才能让它发挥作用?
感谢您的帮助!
【问题讨论】:
标签: node.js express server gzip node-modules