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 questions = [ | |
"What is your name?", | |
"what is your favourite hobby?", | |
"what is your favourite programming language?" | |
]; | |
var answers = []; | |
function askQuestion(i) { |
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
/* | |
Working with Node.js asynchronously through the use of timing functions. | |
The timing functions are:- setTimeout, clearTimeout, setInterval, and clearInterval | |
- setTimeout will create a delay of a certain time and then invoke a callback function | |
*/ | |
var waitTime = 3000; | |
console.log("wait for it"); | |
setTimeout(function(){ |
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
/* | |
Working with Node.js asynchronously through the use of timing functions. | |
The timing functions are:- setTimeout, clearTimeout, setInterval, and clearInterval | |
- setTimeout will create a delay of a certain time and then invoke a callback function | |
- setInterval will not stop, its like a heartbeat | |
- clearInterval & clearTimeout will stop intervals or timeouts that are currently running. | |
*/ | |
var waitTime = 3000; //waitTime is our total time | |
var currentTime = 0; //currentTime is the amount of time that we've waited |
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
/*Readline is a module that allows us to ask questions to our Terminal user. | |
The standard input(stdin) and standard output(stdout) objects that allow | |
us to easily control prompting a user with questions and saving those answers. | |
*/ | |
//create an instance of the readline object which will create the propmt. | |
var readline = require('readline'); | |
var realPerson = { | |
name: '', | |
saying: [] |
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
/*The Event Emitter is Node.js's implementation of the pub/sub design pattern. | |
It allows us to create listeners for an emit custom Events. | |
In fact, every time we've used that on function to listen for a new Event, | |
we've already been using an implementation of the EventEmitter. | |
*/ | |
// create a variable for events and require the events module | |
var events = require('events'); | |
// create a new instance of a variable called emitter by using the new keyword with the event module, .Event Emitter | |
// The EventEmitter is a constructor and we create a new instance of the EventEmitter. |
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 EventEmitter = require('events').EventEmitter; | |
// We can use the utilities module to help us to have the Person object inherit the EventEmitter | |
var util = require('util'); | |
/* -create a Person object | |
-create a constructor function here for this object | |
-in this constructor function, we're going to take in the Person's name | |
*/ | |
var Person = function(name) { | |
// this Person's name will be set to the name value that is passed to this constructor function. |
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 EventEmitter = require('events').EventEmitter; | |
var util = require('util'); | |
var Person = function(name) { | |
this.name = name; | |
}; | |
util.inherits(Person, EventEmitter); | |
/* module.exports = Person; -> object returned by the require export. | |
we could export this, move it to a separate file then require it as a separate module.. |
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
/* | |
- Node.js comes with a Child Process module which allows you to execute external processes in your environment. | |
- In other words, your Node.js app can run and communicate with other applications on the computer that it is hosting | |
- Two main functions used to create Child Processes: spawn and execute | |
- | |
*/ | |
//The Child Process module contains the execute function | |
var exec = require("child_process").exec; | |
//exec('open http'://www.google.com'); |
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
/*alwaysTalking.js | |
var sayings = [ | |
"You may delay, but time will not.", | |
"Tell me and I forget. Teach me and I remember. Involve me and I learn.", | |
"It takes many good deeds to build a good reputation, and only one bad one to lose it.", | |
"Early to bed and early to rise makes a man healthy, wealthy and wise.", | |
"By failing to prepare, you are preparing to fail.", | |
"An investment in knowledge pays the best interest.", | |
"Well done is better than well said." |
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
/* | |
- When we use any methods of the fs module we are given the option to use them synchronously or asynchronously. | |
- reading files synchronously will block the single Node.js thread so all other connections will wait for this synchronous recal | |
*/ | |
//include the file system module - we can do just about anything with files and directories | |
var fs = require('fs'); | |
// create var for files .. | |
// var files = fs.readdirSync('./lib'); //READ FILES FROM LIBRARY FOLDER.. |