bredikhin / barrels

Simple DB Fixtures for Sails.js
MIT License
85 stars 34 forks source link

Cannot find module 'fixtures/development/Group.json #27

Closed luisincrespo closed 9 years ago

luisincrespo commented 9 years ago

Hi. I'm trying to use barrels to seed my db.

I have my JSON files inside _/fixtures/_.

I created a _/seedDevelopment.js_ file with the following content:

var Barrels = require('barrels');
var barrels = new Barrels('./fixtures/');
var fixtures = barrels.data;
barrels.populate(function(err) {
    if (err) {
        return done(err);
    }

    done();
});

When I run

node seedDevelopment.js

I get the following error:

module.js:338 throw err; ^ Error: Cannot find module 'fixtures/Group.json' at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:278:25) at Module.require (module.js:365:17) at require (module.js:384:17) at new Barrels (/Users/lcrespo/Projects/roloegol_backend/node_modules/barrels/index.js:42:30) at Object. (/Users/lcrespo/Projects/roloegol_backend/seedDevelopment.js:2:15) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12)

What am I doing wrong?.

bredikhin commented 9 years ago

What's the structure of the project, what's in the fixtures folder?

luisincrespo commented 9 years ago

I have an api for Group, pretty simple. It has its model Group.js and its controller GroupController.js.

Inside the fixtures I have a Group.json, with the following content:

[
    { 
        "name": "Test" 
    }
]

My development database adapter uses a local mongodb, with sails-mongo.

Before running

node seedDevelopment.js

I lifted the local server as

sails lift

bredikhin commented 9 years ago

Try to pass an absolute path to the Barrels constructor, or build one using process.cwd(), looks like ./... points to a module folder or something.

luisincrespo commented 9 years ago

I'm no longer trying to use Barrels. Went with the "manual" way and seeding the DB on sails bootstrap.js. Thanks anyways for your help bro.