Consulting, training, products, professional services
contact@wearefractal.comOpen source is at github.com/wearefractal
console.log('Hello World');
node helloworld.js
Hello World
var http = require('http');
var server = http.createServer(function (req, res) {
res.writeHead(200);
res.end('Hello World');
});
server.listen(4000);
// Get Users - 20ms
$query = 'SELECT * FROM users WHERE id = ?';
$users = query($query, array($_GET['id']));
print_r($users);
// Get Activities - 130ms
$query = 'SELECT * FROM activities WHERE user_id = ? ORDER BY TIMESTAMP LIMIT 50';
$activities = query($query, array($_GET['id']));
print_r($activities);
// Get Leader Board - 120ms
$query = 'SELECT count(points),user_id FROM activities GROUP BY user_id LIMIT 50';
$leader_board = query($query);
print_r($leader_board);
// Get Users - 20ms
var query = 'SELECT * FROM users WHERE id = ?';
db.query(query, [req.query.id], function (err, users) {
console.log(users);
});
// Get Activities - 130ms
query = 'SELECT * FROM activities WHERE user_id = ? ORDER BY TIMESTAMP LIMIT 50';
db.query(query, [req.query.id], function (err, activities) {
console.log(activities);
});
// Get Leader Board - 120ms
query = 'SELECT count(points),user_id FROM activities GROUP BY user_id LIMIT 50';
db.query(query, function (err, leader_board) {
console.log(leader_board);
});
awesomeFunction(args, function (err, data) {
if (err) {
// Handle Error
}
// Do something awesome with the data
});
npm install <module>
npm find <module>
npm list
var currentCount = 0;
module.exports.incr = function () {
return ++currentCount;
};
var counter = require('./counter');
counter.incr();
var count = counter.inrc();
Keep this in mind... modules are loaded once and cached. So when you load the module a second time in your app, require just returns the cached module object. This lets you do interesting things...
"dependencies": {
"my-module": "https://github.com/my-name/my-module/tarball/master"
}