JavaScript Set 6 Flashcards
What is the filesystem module?
Allows you to work with the file system using node.js
require(“fs”);
What functions can the file system module perform?
- Read files
- Create files
- Update files
- Delete files
- Rename files
What is the URL module?
Splits up a web address into readable parts
What is the url.parse() method?
Returns a URL object with each part
Ex:
q = url.parse(adr)
log(q.host)
log(q.pathname)
log(q.search)
What is the Node.js Crypto module?
Contains OpenSSL and allows you to encrypt and decrypt data
require(“crypto”);
How can you encrypt data with the crypto module?
- Create encryption cipher key with
var key = crypto.Cipher(encryption method, key); - Encrypt the data with the key
var cipherText = key.update(text, encoding method, return format); - Get any remaining encrypted data
cipherText += key.final(return format)
How can you decrypt data with the crypto module?
- Create decryption key with
var key = crypto.Decipher(encryption method, key); - Decrypt the data with the key
var plainText = key.update(input text, input encoding, output encoding); - Get any remaining decrypted data
plainText += key.final(output encoding);
What does the dns module do?
Can convert URLs to IP addresses and vice-versa
require(“dns”);
How do you convert a URL to an IP using the DNS module?
dns.lookup(URL, callback function (err, addresses, family));
How do you convert an IP to a URL using the DNS module?
dns.reverse(IP, callback function (err, url));
What does the events module do?
Allows you to create, fire, and listen for your own events
require(‘events’);
How can you access event properties and methods?
By creating an EventEmitter object
var emitter = new events.EventEmitter();
How do you assign an event handler to an event?
eventEmitter.on(event name, handler function);
How do you fire an event?
eventEmitter.emit(event name);
What does the timer module do?
Contains functions that can execute code after a certain period of time