const fs = require('fs'); const path = require('path'); function getFolderSize(folder) { let totalSize = 0; function calculateFolderSize(folderPath) { const files = fs.readdirSync(folderPath); files.forEach(file => { const filePath = path.join(folderPath, file); const stats = fs.statSync(filePath); if (stats.isDirectory()) { calculateFolderSize(filePath); } else { totalSize += stats.size; } }); } calculateFolderSize(folder); return totalSize; } const folderPath = path.resolve(__dirname, 'node_modules'); const folderSize = getFolderSize(folderPath); console.log(`Size of node_modules: ${(folderSize / 1024 / 1024).toFixed(2)} MB`);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter