简体   繁体   中英

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. 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

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. The path depends on where you are using app.use(express.static(publicDirectoryPath))

    const publicDirectoryPath = path.join(__dirname, '../public'); 

    app.use(express.static(publicDirectoryPath));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM