The File Organizer Script is a lightweight Node.js utility that automatically organizes files in your public/ directory by their file extensions.
It’s perfect for cleaning up messy folders by sorting files like images, PDFs, and text documents into dedicated subfolders (e.g., .jpg → /jpg, .txt → /txt).
✅ Automatically detects file types
✅ Creates folders based on extensions
✅ Skips JavaScript, JSON, and folders
✅ Zero dependencies — pure Node.js
✅ Fast, simple, and beginner-friendly
📁 your-project/
┣ 📂 public/
┃ ┣ 🖼️ image1.png
┃ ┣ 📄 document.txt
┃ ┣ 🎵 song.mp3
┃ ┗ 📂 (organized folders will appear here)
┣ 📜 organize.js
┣ 📜 README.md
┗ 📜 package.json
After running the script, your public/ directory will be neatly organized:
📁 public/
┣ 📂 png/
┃ ┗ image1.png
┣ 📂 txt/
┃ ┗ document.txt
┗ 📂 mp3/
┗ song.mp3
- Node.js version 18+
- A
public/folder containing files you want to organize
git clone https://github.com/atharvashirodkar/nodesorter.git
cd nodesorterNo external dependencies needed — uses built-in Node.js modules (
fs,path,url).
If your file is named organize.js:
node organize.jsYou’ll see:
✅ Files organized successfully!
The script uses Node.js built-in modules:
fsandfs/promisesfor reading and moving filespathfor managing directory pathsurlfor ES module compatibility
- Reads all files from
/public - Detects each file’s extension
- Skips folders,
.js, and.jsonfiles - Creates a new folder for each extension (if not existing)
- Moves files into the correct subfolder
fs.renameSync(
path.join(basePath, item),
path.join(basePath, ext, item)
);Before:
public/
├─ photo.png
├─ report.pdf
├─ notes.txt
After:
public/
├─ png/photo.png
├─ pdf/report.pdf
├─ txt/notes.txt
If you encounter issues:
- Check your Node version (
node -v) - Ensure the
public/folder exists - Verify that files are not currently open by other programs
For bugs or suggestions:
- Open an issue: issues
- Check documentation in
docs/
Contributions are welcome!
To contribute:
- Fork the repo
- Create a new branch (
git checkout -b feature-name) - Commit your changes
- Submit a PR
For detailed guidelines, see CONTRIBUTING.md
- Maintainer:
atharvashirodkar(seepackage.json)
This project is licensed under the MIT License.