$ node > console.log( "Hello, world" ); Hello, world > 2+3 5 > 0 == "" true
# namethatday.js var weekday = require( "weekday" ); var day = weekday( process.argv[2] ); console.log( day.name );
$ node namethatday.js 5 Friday
concat-array
Takes a string and an array of strings and concatenates the first string to each string in the array.
var ca = require('concat-array'); var arr = ['shrimp', 'tron']; console.log(ca.concatArray('jumbo', arr)); # prints [ 'jumbo shrimp', 'jumbo tron' ]
var express = require('express'); var app = express(); app.get('/', function(req, res){ res.send('Hello World'); }); app.listen(3000);
var express = require('express');
var app = express();
app.use(express.basicAuth("testUser", "testPass"));
app.get('/', function(req, res) {
res.send('Hello World');
});
app.listen(3000);
"Everything runs in parallel, except your code"
"Everything runs in parallel, except your code"
"Everything runs in parallel, except your code"
Pros:
"Everything runs in parallel, except your code"
Cons:
var fs = require('fs'); function doSomething(err, contents) { if (err) throw err; console.log(contents); } fs.readFile('myfile.txt', 'utf8', doSomething);
var fs = require('fs');
fs.readFile('myfile.txt', 'utf8', function(err, data) {
if (err) throw err;
console.log(data);
});
$ node cp.js myfile.txt myfile2.txt Copied 4 bytes.
copyFile( process.argv[2], process.argv[3], function(err, length) { if (err) console.log(err); else console.log( "Copied " + length + " bytes." ); } );
function copyFile(infn, outfn, callback) { fs.readFile( infn, function(err, data) { if (err) callback(err); else fs.writeFile( outfn, data, function(err) { if (err) callback(err); else callback(null, data.length); }); }); }
}); }); }); }); }); }); }); }); }); }); }); }); }); }); }); });
Videos | youtube.com/user/ajbalaam |
---|---|
@andybalaam | |
Blog | artificialworlds.net/blog |
Projects | artificialworlds.net |