[英]I am not able to render static images while packaging node-express app using pkg
While trying to render an image from the public folder in my express app it is not rendering it.Can anyone help me how to configure the path so that I am able to render the images or css files in the public folder while creating a executable file using pkg.尝试从我的快速应用程序中的公用文件夹渲染图像时,它没有渲染它。任何人都可以帮助我如何配置路径,以便我能够在创建可执行文件时渲染公用文件夹中的图像或 css 文件使用 pkg。 Attaching the code
附上代码
app.use(express.static(Path.join(__dirname, 'public')));
app.get('/', function(req, res) {
console.log(Path.join(__dirname, 'public/images'));
res.render(Path.join(__dirname, 'views/' + 'testing'), {
variable: Path.join(__dirname, 'public/images/' + 'category.png')
});
});
app.listen(3003, function() {
console.log('listening port 3003');
});
https://www.npmjs.com/package/pkg#detecting-assets-in-source-code https://www.npmjs.com/package/pkg#detecting-assets-in-source-code
Try to move a level up to the ../public
directory in your file path if the express code is at the root level of a directory that is at the same level as the public
directory.如果 express 代码位于与
public
目录处于同一级别的目录的根级别,请尝试将级别向上移动到文件路径中的../public
目录。 The path depends on where you are using app.use(express.static(publicDirectoryPath))
路径取决于您使用
app.use(express.static(publicDirectoryPath))
的位置
const publicDirectoryPath = path.join(__dirname, '../public');
app.use(express.static(publicDirectoryPath));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.