Node Cookbook - Fourth Edition by Bethany Griggs
Author:Bethany Griggs
Language: eng
Format: mobi
Publisher: Packt Publishing Pvt. Ltd.
Published: 2020-11-23T16:00:00+00:00
Run the program, providing a task as an argument to the script:$ node tasks.js "Walk the dog."
Task: 0573rrpo3dpg = Walk the dog.
Now we can persist and list tasks in our LevelDB data store.
How it worksâ¦
The leveldown module is a binding for LevelDB written as a Node.js native module in C++. A Node.js native module provides an interface between the C++ library and JavaScript. The levelup module is a wrapper for the leveldown store that exposes a streaming interface to LevelDB data. Other stores can be used with levelup, as we'll touch on in the There's more⦠section.
When we call levelup(leveldown("./data")), a directory named data is created under our present working directory. This directory holds the data we store in LevelDB.
If a task has been supplied via command-line input, then our addTask() function will be executed. In this function, we create a key for the task. The key for the task starts with Task: and has a random hash appended to it. We use the Math.random() method to create a random hash.
The LevelDB put() method persists data into our LevelDB data store. We pass the put() method the key that we generated, and value, which is the task that was supplied via the command line. The last argument that we supply to the put() method is our callback function. Our callback function catches any errors and then proceeds to run the listTasks() function.
The listTasks() function calls db.createReadStream(), which returns a Readable Stream of the key-value pairs. The createReadStream() method, when supplied with no parameters, will return all key-value pairs stored in our LevelDB data store.
We register a data event handler on the stream returned from the createReadStream() method. Within the data event handler, as data is received, we output it to STDOUT using console.log().
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9926)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9802)
The Mikado Method by Ola Ellnestam Daniel Brolund(9787)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8309)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7789)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7771)
Grails in Action by Glen Smith Peter Ledbrook(7705)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7566)
Windows APT Warfare by Sheng-Hao Ma(6929)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6665)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6526)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6423)
Kotlin in Action by Dmitry Jemerov(5073)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4323)
Solidity Programming Essentials by Ritesh Modi(4054)
Functional Programming in JavaScript by Mantyla Dan(4044)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3845)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3788)
The Ultimate iOS Interview Playbook by Avi Tsadok(3765)
