The only difference with my code and the tutorial is in /server/main.js
import { Meteor } from 'meteor/meteor';
import '../imports/api/tasks.js';
Meteor.startup(() => {
// code to run on server at startup
// start up function that creates entries in the Websites databases.
// code to run on server at startup
if (!Tasks.findOne()){
console.log("No tasks yet. Creating starter data.");
Tasks.insert({
text: "Hello world!",
createdAt: new Date()
});
}
});
But I keep on getting :
W20160520-08:42:51.801(2)? (STDERR) at server/main.js:10:8
W20160520-08:42:51.800(2)? (STDERR) ReferenceError: Tasks is not defined
W20160520-08:42:51.801(2)? (STDERR) at /Users/johannesdejong/Meteor.projects/simple-todos/.meteor/local/build/programs/server/boot.js:290:5
If I read (understand) the load order correctly Load Order /server.main.js should be loaded last and thus after /imports/api/tasks.js where the collection Tasks is defined.
Before meteor 1.3 any file would be evaulated (in a specific order). If you declare variables without var, let or const in a file, this means this variable is global (or at least package scope), but the availability of this variable is dependent on the load-order.
With meteor 1.3 this is still possible, but you can change the load order by importing files like you did.
So if you have declared the Tasks-variable as global in ../imports/api/tasks.js, then your code should work.