var fs = require('fs');
var _ = require('lodash');

var Datastore = require('nedb'),
	db = new Datastore({ filename: './data/xkcd', autoload: true });


module.exports = function (words, callback) {

	db.find({ word: { $in: words } }, function (err, docs) {

		if (err) return callback(err);

		if (!docs.length) {
			callback(null, []);
			return;
		}

		var entries = _.map(docs, 'entries');
		var result = _.intersection.apply(_, entries);

		if (result.length && docs.length == words.length) {
			callback(null, result)
		} else {
			callback(null, [])
		}
	});

}

var fs = require('fs');
var _ = require('lodash');

var Datastore = require('nedb'),
	db = new Datastore({ filename: __dirname + '/data/xkcd', autoload: true });


module.exports = function (words, callback) {

	db.find({ word: { $in: words } }, function (err, docs) {

		if (err) return callback(err);

		if (!docs.length) {
			callback(null, []);
			return;
		}

		var entries = _.map(docs, 'entries');
		var result = _.intersection.apply(_, entries);

		if (result.length && docs.length == words.length) {
			callback(null, result)
		} else {
			callback(null, [])
		}
	});

}

Use an absolute path to load the db file
Use an absolute path to load the db file

This makes it so that the module can also be used in other node projects even when xkcd-cli is contained within the `node_modules` of the depending package