繁体   English   中英

如何在我的角度项目中检查node_modules文件夹是否存在

[英]How to check node_modules folder is there or not in my angular project

我正在尝试使用nodejs在我的angular2项目中检查node_modules文件夹是否存在,但遇到了麻烦。 我是nodejs的新手,所以我不知道该怎么做。 有人可以帮助我吗?

注意:ps->项目名称

您还可以检查角度2项目文件夹的结构: https ://tutorialslink.com/Article_img/Blog_image/689d5f69-71b5-462e-8809-121fa9fd96bc.png

const fullPath = path.dirname("c://mamp/htdocs/projects/ps/src/app/app.component.html");
const regexResp = /^(.*?)node_modules/.exec(fullPath);
const nodemodulesPath = regexResp ? regexResp[1] : fullPath;
console.log(nodemodulesPath );

尝试使用nodejs的fs(filesystem)模块

    const fs = require('fs');
// fs.statSync(path) method returns the instance of fs.Stats
try {
    const stats = fs.statSync("c://mamp/htdocs/projects/ps/node_modules");
    // stats.isDirectory() returns true if file path is Directory, otherwise returns false.
console.log('is directory ? ' + stats.isDirectory());
  } catch(e) {
    console.log("Could not find node modules")
  }

在此处阅读有关此模块的更多信息https://nodejs.org/api/fs.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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