Reputation: 115
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
Upvotes: 0
Views: 538
Reputation: 29
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));
Upvotes: 1