Here is a simple way to solve what you are trying to do
mp3list.html:
<head>
<title>MP3 Collection</title>
</head>
<body>
{{> mp3list}}
</body>
<template name="mp3list">
<ul>
{{#each mp3s}}
<li>{{name}}</li>
{{/each}}
</ul>
</template>
mp3list.js
MP3s = new Mongo.Collection('mp3s');
MP3_DIRETORY = '/tmp/mp3';
INTERVAL_MILLISECONDS = 1000;
if (Meteor.isClient) {
Template.mp3list.helpers({
mp3s: function() {
return MP3s.find();
},
});
}
if (Meteor.isServer) {
var fs = Npm.require('fs');
Meteor.setInterval(function() {
var mp3s = fs.readdirSync(MP3_DIRETORY).filter(
function(i) {
return i.substr(i.length - 4) === '.mp3';
}
);
mp3s.forEach(function(i) { MP3s.upsert({name: i}, { $set: {name: i}}); });
}, INTERVAL_MILLISECONDS);
}
To extend this (i.e. recursive directory search) the answers here provide more details.
However if your app is scanning a large number of files this simple approach will not scale. I'd suggest then looking at ionotify based solutions(assuming linux, other OSs will have similar APIs). watchr
may also be a good option (I haven't used it, or inotify++).