簡體   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