admin管理员组文章数量:1357273
I have a path which is passed down to me as a javascript variable, which will reference to an image (maybe).
../app/assets/icon.png
. In the case that the path is invalid or doesn't exist, I want to use a different file, located somewhere else. In the end, it should look something like this:
var verifiedPath = existsAndIsValid(path) ? path : '../app/default/icon.png'
Is there a simple one-liner in which I can do this?
I have a path which is passed down to me as a javascript variable, which will reference to an image (maybe).
../app/assets/icon.png
. In the case that the path is invalid or doesn't exist, I want to use a different file, located somewhere else. In the end, it should look something like this:
var verifiedPath = existsAndIsValid(path) ? path : '../app/default/icon.png'
Is there a simple one-liner in which I can do this?
Share Improve this question asked Jun 29, 2016 at 19:34 perennial_perennial_ 1,8462 gold badges28 silver badges41 bronze badges1 Answer
Reset to default 8The very simple exists function is deprecated and remends using stat or access instead. They are all core NodeJS.
fs.access('path', fs.R_OK, (err) => {
if (!err) { console.log("File exists");
});
本文标签: nodejsDetermine if path is valid javascriptStack Overflow
版权声明:本文标题:node.js - Determine if path is valid javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744075506a2586671.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论