This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Dependencies | |
*/ | |
fs = require('fs'); | |
/** | |
* DB Initializer | |
*/ | |
var i_mongoose = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sinon = require('sinon'); | |
var chai = require('chai'); | |
expect = chai.expect; | |
should = chai.should(); | |
assert = chai.assert; | |
var clock; | |
beforeEach(function () { | |
clock = sinon.useFakeTimers(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongodb = require('mongodb'); | |
// Connection URL | |
var url = 'mongodb://localhost:27017/scjs'; | |
// Use connect method to connect to the Server | |
mongodb.MongoClient.connect(url, function(err, db) { | |
if(err) { throw err } else { | |
console.log('yahooo'); | |
} | |
}); |
This file has been truncated, but you can view the full file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.provinces.insert( | |
[ { _id: ObjectId("54715c1442d576600a9965fc"), | |
name: 'Araba/Álava', | |
country: 'spain', | |
towns: | |
[ { _id: ObjectId("54715c1442d576600a996630"), | |
name: 'Alegría-Dulantzi', | |
province_id: ObjectId("54715c1442d576600a9965fc") }, | |
{ _id: ObjectId("54715c1442d576600a996631"), | |
name: 'Amurrio', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = fs.readFileSync('/etc/passwd'); | |
/* This code would start 1000 simultaneous asynchronous file reads, and run the do_next_part() | |
function immediately. This has several problems: first, we’d like to wait until | |
all the file reads are done until going further.*/ | |
for(var i = 1; i <= 1000; i++) { | |
fs.readFile('./'+i+'.txt', function() { | |
// do something with the file | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(j = 0; j < provinces.length; j++){ | |
var province = provinces[j]; | |
var province_name = _s.strLeft(province.provincia, '/'); | |
mongo_provinces[j] = { | |
_id: new mongodb.ObjectID() | |
, slug: _s.slugify(province_name) | |
, name: province_name | |
, country: "spain" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var server = new mongodb.Server('localhost', 27017, {auto_reconnect: true, safe: true}); | |
var db = new mongodb.Db('scjs', server); | |
db.open(function(err, db) { if(err) throw err; | |
async.eachSeries( | |
// Collection | |
mongo_provinces |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** Dependencies ***/ | |
var mongoose = require('mongoose') | |
, Schema = mongoose.Schema | |
, ValidationError = require(g.wizco.dirs.libErrors + '/ValidationError'); | |
/** | |
* SuperSchema | |
* Schema mongoose based SuperClass | |
*/ | |
function SuperSchema(schema, _ev) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('another_file.js'); | |
var whatever = 8; | |
function foo(){ | |
// calling a function from another file | |
foo_with_callback(function(returned_value){ | |
console.log(whatever) // whatever is undefined <--- WHY ??? | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** WHY IS THIS IN NODE.JS ? **/ | |
// file1.js | |
var _ = require('underscore'); | |
require('./routes/document'); // _ will be NOT VISIBLE in document | |
// file2.js | |
_ = require('underscore'); | |
require('./routes/document'); // _ will be VISIBLE in document |
OlderNewer