如何在Express中更改默认的lib路径? [英] how to change the default lib path in Express?
问题描述
例如,有路径
/www/node/node_project/public/lib
/www/node/node_project/public/lib
我想将/public/lib移至/lib,但保持node_project运行;因为/lib文件夹与其他项目(可能是PHP项目)共享前端库;那么我该如何移动lib文件夹?!
I want to move /public/lib to /lib, but keep the node_project running; since /lib folder are share front-end libraries with other project (PHP projects maybe); so how can I move the lib folder around?!
推荐答案
您可以将Express静态根文件夹设置为:
You can set the Express static root folder as:
var app = require('express')();
var port = 3000 //The port on which your server listens
app.use(express.static('path to lib folder');
app.listen(port);
如果要指定特定于lib文件夹的路由,则可以将其设置为 app.use(express.static('/your/route',lib文件夹的路径');
If you want to specify a route specific to the lib folder then you can set it as app.use(express.static('/your/route', path to lib folder');
如果您的lib文件夹与初始化express的文件位于同一文件夹,那么您只需提供 app.use(express.static('lib');
If your lib folder is on the same folder as the file that initializes express then you can simply give app.use(express.static('lib');
如果您的 lib文件夹是用于初始化express的文件夹的子文件夹,则可以使用 app.use(express.static(__ dirname +'lib的路径');
If your lib folder is a sub-folder of the folder in which express is initialized then you can use app.use(express.static(__dirname+'path to lib');
如果您的lib文件夹位于任何其他位置,请指定lib文件夹的绝对路径,例如 app.use(express.static('从/到lib的路径);
If your lib folder is on any other location then specify the absolute path to the lib folder like app.use(express.static('path to lib from /');
这篇关于如何在Express中更改默认的lib路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!