Performance: Why path handling matters
MEDIUM IMPACT
This affects server response time and file system access speed, impacting how quickly resources are served to users.
const path = require('path'); const filePath = path.resolve(__dirname, userInputPath); fs.readFile(filePath, (err, data) => { /* ... */ });
const filePath = __dirname + '/' + userInputPath; fs.readFile(filePath, (err, data) => { /* ... */ });
| Pattern | File System Lookups | Error Rate | Response Delay | Verdict |
|---|---|---|---|---|
| Manual string concatenation | Multiple due to invalid paths | High | Increased by 20-50ms | [X] Bad |
| Using path.resolve() | Single accurate lookup | Low | Minimal delay | [OK] Good |