const exec = require('child_process').exec;
const argv = process.argv.slice(2);
const dir = argv[0];
if (!dir) throw new ReferenceError('Missing arg: dir');
exec(`git -C ${dir} log`, (err, log) => {
if (err) throw err;
console.log(log);
});
console.log('Hello!');
require('fs').readFile('./data.json', (err, data) => {
if (err) throw err;
console.log('Wait... Am I?');
console.dir(JSON.parse(data), {depth: null});
});
console.log('I am a unicorn!');
// output:
// Hello!
// I'm a unicorn!
// Wait... Am I still?
// "./data.json" content{
"name": "day-1",
"version": "0.0.0",
"description": "An API server in Hapi.js",
"main": "server.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "mocha",
"start": "bin/www"
},
"repository": {
"type": "git",
"url": "https://github.com/simonrenoult/octo-day-1"
},
"author": "SRE & FJA",
"license": "ISC"
}
$ npm install hapi$ npm install -g nodemon$ npm install --save hapi$ npm install --save-dev mocha$ npm adduser$ npm publishconst http = require('http')
const PORT = 8080
function handleRequest(request, response){
response.end('It Works!! Path Hit: ' + request.url)
}
const server = http.createServer(handleRequest)
server.listen(PORT, function(){
console.log("Server listening on: http://localhost:%s", PORT)
});$ node server.jsOfficial website:
Learn:
Practice: