node package manager

17 results back to index


pages: 628 words: 107,927

Node.js in Action by Mike Cantelon, Marc Harter, Tj Holowaychuk, Nathan Rajlich

Amazon Web Services, business logic, Chris Wanstrath, create, read, update, delete, Debian, en.wikipedia.org, Firefox, Google Chrome, machine readable, MITM: man-in-the-middle, MVC pattern, node package manager, p-value, pull request, Ruby on Rails, SQL injection, web application, WebSocket

Summary Appendix A. Installing Node and community add-ons A.1. OS X setup A.1.1. Installation with Homebrew A.2. Windows setup A.3. Linux setup A.3.1. Ubuntu installation prerequisites A.3.2. CentOS installation prerequisites A.4. Compiling Node A.5. Using the Node Package Manager A.5.1. Searching for packages A.5.2. Installing packages A.5.3. Exploring documentation and package code Appendix B. Debugging Node B.1. Analyzing code with JSHint B.2. Outputting debugging information B.2.1. Debugging with the console module B.2.2. Using the debug module to manage debugging output B.3.

Chapter 13 explains how non-HTTP applications can be created, how to use the Socket.io framework to create real-time applications, and the use of a number of handy build-in Node APIs. Chapter 14, the final chapter, discusses how the Node community works and how Node creations can be published using the Node Package Manager. Code conventions and downloads The code in this book follows common JavaScript conventions. Spaces, rather than tabs, are used for indentation. Lines longer than 80 characters are avoided. In many listings, the code is annotated to point out key concepts. A single statement per line is used and semicolons are added at the end of simple statements.

A package descriptor file If the content of this file seems a bit confusing, don’t worry...you’ll learn more about package.json files in the next chapter and, in depth, in chapter 14. 2.2.4. Installing dependencies With a package.json file defined, installing your application’s dependencies becomes trivial. The Node Package Manager (npm; https://github.com/isaacs/npm) is a utility that comes bundled with Node. It offers a great deal of functionality, allowing you to easily install third-party Node modules and globally publish any Node modules you yourself create. Another thing it can do is read dependencies from package.json files and install each of them with a single command.


Essential TypeScript 4: From Beginner to Pro by Adam Freeman

en.wikipedia.org, Google Chrome, node package manager, revision control, type inference, web application

Run the commands shown in Listing 5-1 to navigate to the tools folder and to tell the Node Package Manager (NPM) to create a file named package.json. This file will be used to keep track of the packages added to the project, as described in the “Using the Node Package Manager” section.cd tools npm init --yes Listing 5-1.Creating the package.json File Use the command prompt to run the commands shown in Listing 5-2 in the tools folder to install the package required for this chapter.npm install --save-dev typescript@4.2.2 npm install --save-dev tsc-watch@4.2.9 Listing 5-2.Adding Packages Using the Node Package Manager The install argument tells NPM to download and add a package to the current folder.

node_modules This folder contains the packages that the application and development tools require, as described in the “Using the Node Package Manager” section. src This folder contains the source code files that will be compiled by the TypeScript compiler. package.json This folder contains the set of top-level package dependencies for the project, as described in the “Using the Node Package Manager” section. package-lock.json This file contains a complete list of the package dependencies for the project. tsconfig.json This file contains the configuration settings for the TypeScript compiler. Using the Node Package Manager TypeScript and JavaScript development depends on a rich ecosystem of packages.

Index A Abstract classes Access control keywords Angular components container data binding decorators injection modules RxJS URL routing any Type disabling implicit use implicit use Arrays empty arrays syntax types inferred types B Bundles C Classes abstract classes access control type guarding concise constructors concise syntax index signatures inheritance read-only properties Collections Compiler automatic code execution configuration configuration file declaration files errors library files setting modules format resolution supported formats polyfilling running the compiler tsconfig.json type inference watch mode Conditional types Constructor functions D Debugging break points debugger keyword remote debugging source maps using Node.js using Visual Studio Code Declaration files Decorators defining enabling metadata uses Definite assignment assertions Docker configuration file creating an image exclusions starting a container Domain Object Model (DOM) API E Enums constant enums implementation limitations string enums using specific values Errata, reporting Examples, complete listings Examples, GitHub repository Examples, omitted content Examples, partial listings F Functions assert functions implicit results overloading types parameters default values null values optional rest parameters type annotations redefining results type annotations void functions G, H Generic types collections conditional types extending classes indexed access operator index type queries index types interfaces iterables iterators method parameters type arguments type guards type inference type mappings type parameters constraining methods multiple parameters Git, installing I Index access operator Index signatures Index types Inferred types Interfaces abstract interfaces extending multiple interfaces optional methods optional properties Intersections correlation merging methods properties Iterators, generic types J, K JavaScript arrays destructuring methods rest expression spreading built-in types checking for errors classes defining inheritance static methods collections Map Set using objects constructor functions, chaining describing types declaration files definitely typed packages generating declaration files third-party code using comments functions arguments arrow functions default parameter values lambda expressions parameters rest parameters results generators including in compilation iterable objects iterators modules objects constructor functions getters and setters inheritance instance properties literal syntax methods private properties properties prototypes static properties type checking optional chaining primitive types private fields Symbol this keyword arrow functions bind method call method methods stand-alone functions type coercion falsy values intentional nullish operator unintentional typeof keyword JavaScript XML Files compiler options factory function props with TypeScript workflow JSDoc comments L Linting configuration rule sets disabling rules installing TSLint running the linter Literal value types functions template strings type overrides M Modules N never type Node.js, installing Node Package Manager commands configuration file local and global packages versions Nullable types removing from a union restricting O Object literals SeeShape types Objects classes constructor functions methods optional properties shape types shape type unions type aliases type comparisons type excess property errors type guards in keyword predicate functions P, Q Packages Editor Git Node.js Node Package Manager R React Babel components hooks containerization deployment hooks JSX production build Redux action creators React-Redux package reducer types toolchain with TypeScript URL routing configuration Read-only properties S Shape types T tsconfig.json File Tuples optional elements using using as a type Type aliases Type annotations Type definitions Type predicate functions Types aliases conditional types generic types guards index types inference intersections literal values shape types type mappings Type unions asserting outside the union defining using U Unit testing configuration creating unit tests installing the test packages matching functions performing tests unknown Type V Version targeting configuration targets Vue.js components lifecycle composition containerization creating the project datastore connecting components mapping functions deployment directives production build toolchain with TypeScript URL routing Vuex W, X, Y, Z Webpack development server workflow


pages: 180 words: 37,187

AngularJS Essentials by Rodrigo Branas

business logic, Firefox, MVC pattern, node package manager, single page application, web application

^ parameter 45 A AngularJS about 7 architectural concepts 9 built-in services 76 data handling 53 history 8 service, creating 69 URL 12, 120 AngularJS $compile documentation URL 47 AngularJS animation about 48 ngClass directive, animating 50 ngHide directive, animating 50 ngRepeat directive, animating 49 working 48 AngularJS built-in directives ngApp directive 19, 20 ngBind directive 21 ngBindHtml directive 22 ngClass directive 27 ngClick directive 25, 26 ngController directive 20 ngDisable directive 26 ngHide directive 31 ngIf directive 31 ngInclude directive 31 ngModel directive 24 ngOptions directive 28-30 ngRepeat directive 22, 23 ngShow directive 30 ngStyle directive 30 other directives 26 using 19 AngularJS built-in services $timeout service 96 asynchronous implementation 98 backend communication 76 logging strategy 96 AngularJS components $httpBackend service, mocking with 132-139 controller 126 directives 129 filters 128 service 125 testing 124 test, running with Karma 140 application organization refactoring 32 architectural concepts, AngularJS controller 9 framework, setting up 10, 11 model 9 view 9 array, orderBy filter 59 Asynchronous JavaScript and XML (AJAX) 79, 80 autoWatch property 142 B backend communication about 76 AJAX 79 caching mechanism 85 headers 84 HTTP 76 HTTP facade, creating 82 interceptors 85, 86 JSON 76, 77 REST method 77 best practices, scope object 106 bootstrapping process 18 Bower about 156 cache 158 installation 156 packages, managing with 156 used, for installing packages 157 used, for searching packages 156 bower.json file 157 C cache, Bower 158 caching mechanism 85 callback 98 code organization about 12, 13 ways 13 code organization, ways domain style 15 inline style 13 specific style 14 stereotyped style 13, 14 cohesion 67 Common Gateway Interface (CGI) 7 compile function used, for creating directive 47 configuration, Grunt 146 constants 74 Content Delivery Network (CDN) URL 12 controller, AngularJS components testing 126 controller function used, for creating directive 46 coupling 68 currency filter 56 D date filter 56 deferred API about 100 notify(value) function 100 reject(reason) function 100 resolve(result) function 100 dependency injection 68, 69 directive 18, 19 directive configuration compile function, using 47 controller function, using 46 link function, using 43 replace property, using 36 require property, using 44-46 restrict property, using 37, 38 scope property, using 38-41 template property, using 35 templateUrl property, using 36 transclude property, using 42 Directive Definition Object 34 directives, AngularJS components compiling 130 creating 18, 34 digest cycle, invoking 130 element, creating 130 [ 160 ] link function, calling with scope 130 testing 129 directive scope configuring 38 distribution package creating, for performance improvement 147 creating, for quality improvement 147 creating, for security improvement 147 grunt-connect plugin, installing 153-155 grunt-contrib-clean plugin, installing 147, 148 grunt-contrib-concat plugin, installing 149 grunt-contrib-copy plugin, installing 150 grunt-contrib-jshint plugin, installing 148 grunt-contrib-uglify plugin, installing 149 grunt-karma plugin, installing 151 Document Object Model (DOM) 17 domain style 15 E expression about 53, 54 interpolation 53 F factory function about 70 used, for creating services 70-73 filters about 55 creating 61 interacting, with expression 55 testing 128 using, in other components 60 filter usage, with expression about 56, 57 currency filter, using 55, 56 date filter, using 56 json format, using 57 limitTo filter, using 58 lowercase filter, using 58 number filter, using 58 orderBy filter, using 59, 60 uppercase filter, using 60 form validation $dirty object 65 $error object 65 $pristine object 65 about 62 basic validation, adding 63, 64 first form, creating 62 framework, AngularJS setting up 10-12 function, orderBy filter 59 G GET method 76 Git repository 156, 157 Google Web Toolkit (GWT) 8 Grunt configuration 146 distribution package, creating 147 installing 146 workflow, automating with 145 workflow, executing 155 grunt-connect plugin installing 153-155 grunt-contrib-clean plugin installing 147, 148 grunt-contrib-concat plugin installing 149 grunt-contrib-copy plugin installing 150 grunt-contrib-jshint plugin installing 148 grunt-contrib-uglify plugin installing 149 Gruntfile.js file 146 grunt-karma plugin installing 151 H headers, backend communication 84, 85 HyperText Markup Language (HTML) 7 HyperText Transfer Protocol (HTTP) 7 I Immediately-Invoked Function Expression (IIFE) 71 inline style 13 installation, Bower 156 [ 161 ] installation, Grunt 146 installation, grunt-connect plugin 153-155 installation, grunt-contrib-clean plugin 147, 148 installation, grunt-contrib-concat plugin 149 installation, grunt-contrib-copy plugin 150 installation, grunt-contrib-uglify plugin 149 installation, grunt-karma plugin 151 installation, packages Bower used 157 interceptors httpTimestampInterceptor 85 httpUnauthorizedInterceptor parameter 86 request interceptor 85 response interceptor 86 J Jasmine 121 Jasmine testing framework about 122-124 URL 122 JavaScript Object Notation (JSON) 57, 77 jQuery library URL 104 JSHint 121, 147 JSLint 121, 147 K Karma about 140 configuring 141 configuring, browser options 141 installing, prerequisites 140 tests, running with 140-142 L limitTo filter 58 link function attrs 43 calling, with scope 130 ctrl 43 element 43 scope 43 transcludeFn 43 used, for creating directive 43 logging strategy levels 96 low cohesion application 67 lowercase filter 58 M Mocha, Karma 141 Model-View-Controller (MVC) pattern 9 Model-View-Whatever (MVW) 9 modules creating 115 parking application 115, 119, 120 search 115, 118, 119 UI 115-118 N nested controllers, ngController directive 21 new operator 74 ngApp directive 19, 20 ngBind directive 21 ngBindHtml directive 22 ngClass directive about 27 animating 50 ngClick directive 25, 26 ngController directive about 20 nested controllers 21 ngDisable directive 26 ngHide directive about 31 animating 50 ngIf directive 31 ngInclude directive 31 ngModel directive 24 ngOptions directive 28-30 ngRepeat directive about 22, 23 animating 49 ngShow directive 30 ngStyle directive 30 NodeJS 146 Node Package Manager (npm) 141, 146 number filter 58 [ 162 ] O one-way data binding mechanism 103 orderBy filter about 59, 60 array 59 function 59 string property 59 P package.jsonfile file 146, 154, 155 packages installing, with Bower 157 managing, with Bower 156 searching, with Bower 156 using 157 parking application module 115, 119, 120 Plain-Old-JavaScript-Object (POJO) 9 POST method 77 prerequisites, Karma installation NodeJS 140 Node Package Manager(npm) 141 promise API catch(errorCallback) 101 finally(callback) 101 then (successCallback, errorCallback, notifyCallback) 101 provider used, for creating services 75, 76 Q QUnit, Karma 141 R recommended modules, AngularJS 120 replace property used, for creating directive 36 Representational State Transfer (REST method) 77 RequireJS, Karma 141 require property used, for creating directive 44-46 restrict property used, for creating directive 37, 38 Revealing Module Pattern 70, 72, 122 RSpec 122 run function 112 S scope object about 103 best practices 106-110 broadcasting 111, 112 scope property used, for creating directive 38-41 search module 115, 118, 119 services, AngularJS components creating 69 creating, with AngularJS service 74 creating, with factory function 70-73 creating, with provider 75, 76 testing 125 single-page application.

The tool is the result of his Master's thesis called JavaScript Test Runner, for the Czech Technical University in Prague. Installation Before installing Karma, you need to have the NodeJS already installed. It is a quite simple process, and you just need to visit their website, download the package, and proceed with installation. [ 140 ] Chapter 7 After this, you can use the Node Package Manager, also known as npm. It will manage the installation of everything that we need to set up our environment, as follows: npm install –g karma Configuration The configuration is quite simple. It just requires a file called karma.conf.js, located in the root application directory. The best way to create it is by following the configuration wizard through the following command: karma init Karma's configurator will be shown, and you just have to follow the instructions in order to generate your configuration file.

It works over plugins, and there is a huge ecosystem with thousands of choices just waiting to be downloaded! We also have the opportunity to create our own plugins and share them within the community. The warranty is that all of the required tasks of our workflow will be fulfilled! Automating the Workflow Installation Just like Karma, Grunt requires NodeJS and the Node Package Manager to be installed. To proceed with the installation, we just need to type in the following command: npm install -g grunt-cli grunt After this, we are ready to configure it! Configuration The Gruntfile.js file is the JavaScript file that defines the configuration of each task, plugin, and workflow.


pages: 325 words: 85,599

Professional Node.js: Building Javascript Based Scalable Software by Pedro Teixeira

en.wikipedia.org, false flag, Firefox, Google Chrome, node package manager, platform as a service, SQL injection, web application, WebSocket

Then run the file by passing the file path as first argument to the Node executable while inside a shell prompt. For example: $ node hello_world.js Hello World! You can quit the CLI by typing Ctrl+D or Ctrl+C. SETTING UP AND USING NODE PACKAGE MANAGER You can only get so far using the language features and the core functions. That’s why most programming platforms have a system in place that allows you to download, install, and manage third-party modules. In Node, you have Node Package Manager (NPM). NPM is three things — a third-party package repository, a way to manage packages installed in your computer, and a standard to define dependencies on other packages.

CONTENTS Introduction Part I: Introduction and Setup Chapter 1: Installing Node Installing Node on Windows Installing on Mac OS X Installing Node Using the Source Code Setting Up and Using Node Package Manager Summary Chapter 2: Introducing Node Introducing the Event-Driven Programming Style How Node and JavaScript Make Writing Asynchronous Applications Easier Summary Part II: Node Core API Basics Chapter 3: Loading Modules Understanding How Node Loads Modules Exporting a Module Summary Chapter 4: Using Buffers to Manipulate, Encode, and Decode Binary Data Creating a Buffer Getting and Setting Bytes in a Buffer Slicing a Buffer Copying a Buffer Decoding a Buffer Summary Chapter 5: Using the Event Emitter Pattern to Simplify Event Binding Understanding the Standard Callback Pattern Understanding the Event Emitter Pattern Understanding Event Types Using the Event Emitter API Creating an Event Emitter Summary Chapter 6: Scheduling the Execution of Functions Using Timers Using setTimeout to Defer the Execution of a Function Using clearTimeout to Cancel the Execution of a Function Scheduling and Canceling the Repetitive Execution of a Function Using process.nextTick to Defer the Execution of a Function Until the Next Event Loop Iteration Blocking the Event Loop Escaping the Event Loop Using setTimeout Instead of setInterval to Force Serialization Summary Part III: Files, Processes, Streams, and Networking Chapter 7: Querying, Reading From, and Writing to Files Manipulating File Paths Introducing the fs Module Opening a File Reading from a File Summary Chapter 8: Creating and Controlling External Processes Executing External Commands Spawning Child Processes Signaling and Killing Processes Summary Chapter 9: Reading and Writing Streams of Data Using a Readable Stream Using Writable Streams Considering Some Stream Examples Avoiding the Slow Client Problem and Saving Your Server Summary Chapter 10: Building TCP Servers Creating a TCP Server Building a Simple TCP Chat Server Summary Chapter 11: Building HTTP Servers Understanding the http.ServerRequest Object Understanding the http.ServerResponse Object Streaming HTTP Chunked Responses Shutting Down the Server Example 1: Building a Server that Serves Static Files Example 2: Making Use of HTTP Chunked Responses and Timers Summary Chapter 12: Building a TCP Client Connecting to a Server Sending and Receiving Data Ending the Connection Handling Errors Building an Example Command-Line TCP Client Summary Chapter 13: Making HTTP Requests Making GET Requests Using Other HTTP Verbs Pooling Sockets Using http.Agent Using a Third-Party Request Module to Simplify HTTP Requests Summary Chapter 14: Using Datagrams (UDP) Understanding UDP Understanding the Uses of UDP Building a Datagram Server Creating a Simple Datagram Echo Server Building a Datagram Client Creating a Simple Datagram Command-Line Client Understanding and Using Datagram Multicast Summary Chapter 15: Securing Your TCP Server With TLS/SSL Understanding Private and Public Keys Building a TLS Server Building a TLS Client Building Some Examples Summary Chapter 16: Securing Your HTTP Server With HTTPS Building a Secure HTTP Server Creating an HTTPS Client Summary Part IV: Building and Debugging Modules and Applications Chapter 17: Testing Modules and Applications Using a Test Runner Using an Assertion Testing Module Testing Your Asynchronous Module Summary Chapter 18: Debugging Modules and Applications Using console.log Using Node’s Built-in Debugger Using Node Inspector Summary Chapter 19: Controlling the Callback Flow Understanding the Boomerang Effect Avoiding the Boomerang Effect by Declaring Functions Using the async Flow Control Library Summary Part V: Building Web Applications Chapter 20: Building and Using HTTP Middleware Understanding the Connect HTTP Middleware Framework Building Your Own HTTP Middleware Using the HTTP Middleware Bundled in Connect Summary Chapter 21: Making a Web Application Using Express.js Initializing Your Express.js Application Setting Up Middleware in Your Application Routing Requests Summary Chapter 22: Making Universal Real-Time Web Applications Using Socket.io Understanding How WebSockets Work Using Socket.IO to Build WebSocket Applications Summary Part VI: Connecting to Databases Chapter 23: Connecting to MYSQL Using node-mysql Using a Library to Connect to and Communicate with a MySQL Database Adding Data to the Database with Security Concerns in Mind Reading Data Efficiently Summary Chapter 24: Connecting to CouchDB Using Nano Installing Nano Connecting and Creating a Database Storing Documents Creating and Using CouchDB Views Attaching Files to a CouchDB Document Summary Chapter 25: Connecting to MongoDB Using MongooSE Installing Mongoose Understanding How Mongoose Uses Models to Encapsulate Database Access Connecting to MongoDB Defining a Schema Defining a Model Summary Introduction Advertisements Part I Introduction and Setup CHAPTER 1: Installing Node CHAPTER 2: Introducing Node Chapter 1 Installing Node WHAT’S IN THIS CHAPTER?

CONTENTS Introduction Part I: Introduction and Setup Chapter 1: Installing Node Installing Node on Windows Installing on Mac OS X Installing Node Using the Source Code Setting Up and Using Node Package Manager Summary Chapter 2: Introducing Node Introducing the Event-Driven Programming Style How Node and JavaScript Make Writing Asynchronous Applications Easier Summary Part II: Node Core API Basics Chapter 3: Loading Modules Understanding How Node Loads Modules Exporting a Module Summary Chapter 4: Using Buffers to Manipulate, Encode, and Decode Binary Data Creating a Buffer Getting and Setting Bytes in a Buffer Slicing a Buffer Copying a Buffer Decoding a Buffer Summary Chapter 5: Using the Event Emitter Pattern to Simplify Event Binding Understanding the Standard Callback Pattern Understanding the Event Emitter Pattern Understanding Event Types Using the Event Emitter API Creating an Event Emitter Summary Chapter 6: Scheduling the Execution of Functions Using Timers Using setTimeout to Defer the Execution of a Function Using clearTimeout to Cancel the Execution of a Function Scheduling and Canceling the Repetitive Execution of a Function Using process.nextTick to Defer the Execution of a Function Until the Next Event Loop Iteration Blocking the Event Loop Escaping the Event Loop Using setTimeout Instead of setInterval to Force Serialization Summary Part III: Files, Processes, Streams, and Networking Chapter 7: Querying, Reading From, and Writing to Files Manipulating File Paths Introducing the fs Module Opening a File Reading from a File Summary Chapter 8: Creating and Controlling External Processes Executing External Commands Spawning Child Processes Signaling and Killing Processes Summary Chapter 9: Reading and Writing Streams of Data Using a Readable Stream Using Writable Streams Considering Some Stream Examples Avoiding the Slow Client Problem and Saving Your Server Summary Chapter 10: Building TCP Servers Creating a TCP Server Building a Simple TCP Chat Server Summary Chapter 11: Building HTTP Servers Understanding the http.ServerRequest Object Understanding the http.ServerResponse Object Streaming HTTP Chunked Responses Shutting Down the Server Example 1: Building a Server that Serves Static Files Example 2: Making Use of HTTP Chunked Responses and Timers Summary Chapter 12: Building a TCP Client Connecting to a Server Sending and Receiving Data Ending the Connection Handling Errors Building an Example Command-Line TCP Client Summary Chapter 13: Making HTTP Requests Making GET Requests Using Other HTTP Verbs Pooling Sockets Using http.Agent Using a Third-Party Request Module to Simplify HTTP Requests Summary Chapter 14: Using Datagrams (UDP) Understanding UDP Understanding the Uses of UDP Building a Datagram Server Creating a Simple Datagram Echo Server Building a Datagram Client Creating a Simple Datagram Command-Line Client Understanding and Using Datagram Multicast Summary Chapter 15: Securing Your TCP Server With TLS/SSL Understanding Private and Public Keys Building a TLS Server Building a TLS Client Building Some Examples Summary Chapter 16: Securing Your HTTP Server With HTTPS Building a Secure HTTP Server Creating an HTTPS Client Summary Part IV: Building and Debugging Modules and Applications Chapter 17: Testing Modules and Applications Using a Test Runner Using an Assertion Testing Module Testing Your Asynchronous Module Summary Chapter 18: Debugging Modules and Applications Using console.log Using Node’s Built-in Debugger Using Node Inspector Summary Chapter 19: Controlling the Callback Flow Understanding the Boomerang Effect Avoiding the Boomerang Effect by Declaring Functions Using the async Flow Control Library Summary Part V: Building Web Applications Chapter 20: Building and Using HTTP Middleware Understanding the Connect HTTP Middleware Framework Building Your Own HTTP Middleware Using the HTTP Middleware Bundled in Connect Summary Chapter 21: Making a Web Application Using Express.js Initializing Your Express.js Application Setting Up Middleware in Your Application Routing Requests Summary Chapter 22: Making Universal Real-Time Web Applications Using Socket.io Understanding How WebSockets Work Using Socket.IO to Build WebSocket Applications Summary Part VI: Connecting to Databases Chapter 23: Connecting to MYSQL Using node-mysql Using a Library to Connect to and Communicate with a MySQL Database Adding Data to the Database with Security Concerns in Mind Reading Data Efficiently Summary Chapter 24: Connecting to CouchDB Using Nano Installing Nano Connecting and Creating a Database Storing Documents Creating and Using CouchDB Views Attaching Files to a CouchDB Document Summary Chapter 25: Connecting to MongoDB Using MongooSE Installing Mongoose Understanding How Mongoose Uses Models to Encapsulate Database Access Connecting to MongoDB Defining a Schema Defining a Model Summary Introduction Advertisements Part I Introduction and Setup CHAPTER 1: Installing Node CHAPTER 2: Introducing Node Chapter 1 Installing Node WHAT’S IN THIS CHAPTER? Getting Node up and running Installing Node Package Manager (NPM) Using NPM to install, uninstall, and update packages At the European JSConf in 2009, Ryan Dahl, a young programmer, presented a project he had been working on. This project was a platform that combined Google’s V8 JavaScript engine, an event loop, and a low-level I/O API. This project was not like other server-side JavaScript platforms where all the I/O primitives were event-driven and there was no way around it.


Learning Node.js: A Hands-On Guide to Building Web Applications in JavaScript by Marc Wandschneider

business logic, database schema, en.wikipedia.org, Firefox, functional programming, Google Chrome, node package manager, telemarketer, web application

I showed it to you here so that you can recognize it for what it is when you see it, but you will almost never use it in this book or your projects—you will largely stick with the factory model. npm: The Node Package Manager Apart from writing your own modules and using those provided by Node.js, you will frequently use code written by other people in the Node community and published on the Internet. The most common way this is done today is by using npm, the Node Package Manager. npm is installed with your node installation (as you saw in Chapter 1, “Getting Started”), and you can go to the command line and type npm help to verify that it’s still there and working.

Maintaining a Sense of Identity Being Polite—Learning to Give Up Control Synchronous Function Calls Summary Part II: Learning to Run 4 Writing Simple Applications Your First JSON Server Returning Some Data Node Pattern: Asynchronous Loops Learning to Juggle: Handling More Requests More on the Request and Response Objects Increased Flexibility: GET Params Modifying Things: POST Data Receiving JSON POST Data Receiving Form POST Data Summary 5 Modules Writing Simple Modules Modules and Objects npm: The Node Package Manager Consuming Modules Searching for Modules Module Caching Cycles Writing Modules Creating Your Module Developing with Your Module Publishing Your Modules A Module So Common It Should Be Built In The Problem The Solution Summary 6 Expanding Your Web Server Serving Static Content with Streams Reading a File Serving Static Files in a Web Server with Buffers Serving Up More Than Just HTML Assembling Content on the Client: Templates The HTML Skeleton Page Serving Static Content Modifying Your URL Scheme The JavaScript Loader/Bootstrapper Templating with Mustache Your Home Page Mustache Template Putting It All Together Summary Part III: Writing Web Applications 7 Building Web Applications with Express Installing Express Hello World in Express Routing and Layers in Express Routing Basics Updating Your Photo Album App for Routing REST API Design and Modules API Design Modules Additional Middleware Functionality Usage Configurations Ordering of Middleware Static File Handling POST Data, Cookies, and Sessions Better Browser Support for PUT and DELETE Compressing Output HTTP Basic Authentication Error Handling Summary 8 Databases I: NoSQL (MongoDB) Setting Up MongoDB Installing MongoDB Using MongoDB in Node.js Structuring Your Data for MongoDB It’s All JavaScript Data Types Understanding the Basic Operations Connecting and Creating a Database Creating Collections Inserting Documents into Collections Updating Document Values Deleting Documents from Collections Querying Collections Updating Your Photo Albums App Writing the Low-Level Operations Modifying the API for the JSON Server Updating Your Handlers Adding Some New Pages to the Application Recapping the App Structure Summary 9 Databases II: SQL (MySQL) Getting Ready Installing MySQL Adding the mysql Module from npm Creating a Schema for the Database Basic Database Operations Connecting Adding Queries Adding Authentication to the Application Updating the API to Support Users Examining the Core User Data Operations Updating the Express Application Creating the User Handler Creating the Login and Register Pages Resource Pooling Getting Started Working with Connections Authenticating the API Summary Part IV: Getting the Most Out of Node.js 10 Deployment and Development Deployment Level: Basic Level: Ninja Multiprocessor Deployment: Using a Proxy Multiple Servers and Sessions Virtual Hosting Built-in Support Proxy Server Support Securing Your Projects with HTTPS/SSL Generating Test Certificates Built-in Support Proxy Server Support Multiplatform Development Locations and Configuration Files Handling Path Differences Summary 11 Command-Line Programming Running Command-Line Scripts UNIX and Mac Windows Scripts and Parameters Working with Files Synchronously Basic File APIs Files and Stats Listing Contents of Directories Interacting with the User: stdin/stdout Basic Buffered Input-Output Unbuffered Input The Readline Module Working with Processes Simple Process Creation Advanced Process Creation with Spawn Summary 12 Testing Choosing a Framework Installing Nodeunit Writing Tests Simple Functional Tests Testing Asynchronous Functionality RESTful API Testing Testing Secured Resources Summary Index Acknowledgments I’d like to thank all the Marks at PHPTR (it’s a common name, it seems) who have helped me make this book and other projects a reality.

In addition to all the already-powerful and functional modules that Node provides for you, there is a huge community further developing modules that you can take advantage of in your programs, and indeed you can even write your own to give something back! One of the cool things about Node is that you don’t really distinguish between modules that you have produced and modules that you consume from external repositories, such as those you see later in this chapter via npm, the Node Package Manager. When you write separate classes and groups of functions in Node, you put them in basically the same format—perhaps with a bit less dressing and documentation—as modules you download from the Internet and use. In fact, it usually takes only an extra bit of JSON and maybe a line or two of code to prepare your code for consumption by others!


pages: 290 words: 119,172

Beginning Backbone.js by James Sugrue

Airbnb, business logic, continuous integration, don't repeat yourself, Firefox, Google Chrome, loose coupling, MVC pattern, node package manager, single page application, web application, Y Combinator

You will need Node.js installed on your development or build machine to run precompilation. In Chapter 3, we created a Node.js server to act as a backend to our application. If you haven’t already installed node.js, you can download it from http://nodejs.org. Once you have node.js installed, you can use the node package manager (NPM) to download the handlebars package. npm install handlebars -g All templates will need to be stored in an external file, which is passed to the precompiler on the command line. handlebars<inputfile> -f <outputfile> This will result in a JavaScript file being created that contains the compiled template, which can then be included within your application.

Installation instructions for PhantomJS are available on the project web site under http://phantomjs.org/download.html, as illustrated in Figure 8-6, where you will be instructed to download the appropriate installer for your operating system. However, if you are already using Node.js, you can use the Node Package Manager to install PhantomJS by using the following command: npm install phantomjs 162 Chapter 8 ■ Testing Your Backbone.js Application Figure 8-6. PhantomJS web site at http://phantomjs.org Now that you have PhantomJS installed, you will need to obtain the PhantomJS Runner plug-in for QUnit, runner.js, from https://github.com/jquery/qunit/tree/master/addons/phantomjs.

If you’ve been following the examples in this book, you will already have Node.js installed. If you haven’t, go to http://nodejs.org and follow the installation steps for your operating system. 180 Chapter 9 ■ Using Grunt for Your Build Process The Grunt command-line interface (CLI) is installed through the Node Package Manager by executing the following on the command line, using the -g flag to ensure it is installed globally. Note that you will need to execute this with admin rights; on Mac OS X this means prefixing the command with sudo. npm install -g grunt-cli To check that it has successfully installed, run grunt --help from the command line.


pages: 273 words: 72,024

Bitcoin for the Befuddled by Conrad Barski

Airbnb, AltaVista, altcoin, bitcoin, blockchain, buttonwood tree, cryptocurrency, Debian, en.wikipedia.org, Ethereum, ethereum blockchain, fiat currency, Isaac Newton, MITM: man-in-the-middle, money: store of value / unit of account / medium of exchange, Network effects, node package manager, p-value, peer-to-peer, price discovery process, QR code, radical decentralization, Satoshi Nakamoto, self-driving car, SETI@home, software as a service, the payments system, Yogi Berra

Installing Node.js You first need to download an installer for Node.js from the http://nodejs.org/ website. When you run the installer for Node.js, it will also install the Node Package Manager (npm) that we’ll rely on next. Installing node-bitcoin Now you’ll need a JavaScript library that connects to Bitcoin Core and bitcoind. We’ll use the node-bitcoin library. To install node-bitcoin, go to a command prompt and enter npm install bitcoin. This command invokes the (previously installed) Node Package Manager, which downloads everything in the library in a simple step. Starting Bitcoin Core If you haven’t already, download Bitcoin Core from its official website at http://bitcoin.org/en/download.

Instead, look online for information about installing the Oracle JDK on your version of Linux and make it the default Java version on your system. Step 2: Installing Maven Maven is a packaging tool for Java. Essentially, you specify which libraries your program needs, and Maven automatically downloads them from the Internet and makes them available to your program. This is analogous to the Node Package Manager used in Appendix A. You can download Maven and find instructions for installing Maven on each OS at https://maven.apache.org/. Just follow the instructions at the main Maven website to install it or search Google for tutorials. Because more than a million other people have had to install Maven, if you run into installation problems, just type your problem into Google.

program, 217–218, 220–222 hello-money starter project creating, 228–229 declarations, 231 hook for detecting money arrival, 234 running and testing, 235–236 writing code, 230–235 hierarchical deterministic wallets, 190 Hill, Austin, 120 history of Bitcoin, 112–116 homebrew (command-line tool), 219 hosted wallets online services, 36 vs. personal wallets, 34–35 hot storage, 47 vs. cold storage, 33–34 hot wallets, personal, 37–38 human-readable Bitcoin addresses, 10n hybrid wallets, 187 I illegal activity, Bitcoin and, 124 impedance mismatch, 57 importing private key, 17, 39, 193, 194–195, 237 installing SPV wallets vs. full wallets, 193 integer factorization, 131 Internet bubble, 120 InterruptedException exception type, 239 irreversibility, of transactions, 25–26, 56 superiority of, 57 J Java, 226 initializing objects, 231–233 installing, 226–227 java.io.File class, 231 Java JDK (Java Development Kit), 226 java.matho.BigInteger class, 231 JavaScript, 213–223 preparing machine for, 218–219 writing Bitcoin program in, 217–218 jelly-filled donut incident, 141–156 JSON-RPC API (JavaScript Object Notation - Remote Protocol Call), 222 limitations of writing Bitcoin programs using, 223 JSON-RPC protocol, 214 K Kaminsky, Dan, 118 Keynesian economics, 126 Kienzle, Jörg, 110–111 Koblitz curve, 151 Kraken, 64 Krugman, Paul, 117 L Landauer limit, 157 laptops, private keys on, 44 ledger, 11 length extension, 171n liability, for stolen bitcoins, 34 lightweight wallets, 192 limit orders, 66 Linux installing Git, 227 installing Maven, 227 OpenJDK version of Java, 227 setting up Bitcoin Core server, 219 live Bitcoin exchanges, 71 LocalBitcoins.com, 67, 68 escrow service, 70 M Mac OS installing Git, 227 installing Maven, 227 setting up Bitcoin Core server, 219 man-in-the-middle attacks, 216 market orders, 65–66 MasterCard, 112 master private key, 188 master public key, 188 generating Bitcoin address with, 190 Maven empty starter project created with, 228 installing, 227 mBTC (millibitcoins), 9 MD5 (message digest algorithm), 132 meeting places, for Bitcoin transactions, 68 MemoryBlockStore function (bitcoinJ), 237 merchant services, 214 Merkle trees, 192 mesh networks, 169 message digest algorithm (MD5), 132 microbitcoins (µBTC), 9 middleman, buying bitcoins from, 52–57 Miller-Rabin primality test, 90 millibitcoins (mBTC), 9 mining, 5, 20, 26–27, 96, 99, 161–180 in 2030, 201–202 decentralization of, 179–180 difficulty of, 173 distributing new currency with, 167–168 hardware, 174–175 2030 requirements, 202 energy efficiency of, 178 profitability threshold curves for comparing, 179 need for, 162–168 nodes, 170 pooled, 175–176 practicality, 50 preventing attacks with, 166–167 process for, 168–176 for profit, 176–177 proof-of-work in, 138–139 solving a block, 171 modular arithmetic, 131n “m of n” private key, 42 money laundering, 112–113 Moore’s law, 179n Moxie Jean, 67 Multibit, 38 multi-signature addresses, and fragmented private keys, 41–42 multi-signature transactions, 57, 69–70 mvn install command, 230 My Wallet Service, 37 N Nakamoto, Satoshi, 3, 110, 211 identity, 113 last comment, 114 white paper on Bitcoin, 112 network effect, 120 NetworkParameters structure, 232 newbiecoins.com, 13 newly minted bitcoins, 26–27 Newton, Isaac, Principia, 210–211 node-bitcoin, installing, 218 Node.js library, 217, 221 installing, 218 Node Package Manager, 218 nodes broadcast only, 169 full, 191 relay, 170 nominal deflation, 126 nonprofit organizations, accepting bitcoins, 18 NXT, 125 O off-chain transactions, 201 offline transaction signing, 40–41 onCoinsReceived function, 234–235 online wallet services hosted, 36 personal, 34, 37 Oracle Corporation, 226 orders, placing to buy bitcoins, 65 order of curve, elliptic curve cryptography, 152–153 orphaned blocks, 24–25 P paper money, color copiers as threat, 110 paper wallets, 39 encrypted, 39–40 passwords, 14, 40 for brain wallet, 45 function of, 40 loss of, 37 Peercoin, 125 PeerGroup object, 233–234, 240 peer-to-peer architecture, 119 pegging, 120 pending transaction, 18 Perrig, Adrian, 110–111 personal wallets vs. hosted wallet, 34–35 hot storage, 37–38 online services, 37 person-to-person bitcoin purchases, 52, 67–71 point multiplication, 150, 158–159 point-of-sale terminals, watch-only wallet for, 187 polling, Bitcoin programming, 223 pom.xml file, 229, 236–237 pooled mining, 175–176 portability, of currency, 117 Preneel, Bart, 140 price discovery process, 120 privacy, 11n and criminals, 124 multiple addresses and, 12 private currencies, 2 private key, 11–12, 150 compromise of, 41 extra protection for, 139 fragmented, and multi-signature addresses, 41–42 generating, 37 importing, 237 master, 188 memorizing, 45 parable on, 141–145 reversing function of, 136 security for, 39, 186 signing transaction with, 156 SPV wallets vs. full wallets, 194 storing, 33 profit, mining for, 176–177 programming languages, for Bitcoin network connection, 225–226 proof-of-stake, 125 proof-of-work, 125, 166 and blockchain, 165 in mining, 138–139 protecting bitcoins, 61.


pages: 190 words: 52,865

Full Stack Web Development With Backbone.js by Patrick Mulder

Airbnb, business logic, create, read, update, delete, Debian, functional programming, Kickstarter, MVC pattern, node package manager, Ruby on Rails, side project, single page application, web application, WebSocket

Send email to index@oreilly.com. 165 Backbone.Collection, sorting/filtering models with, 61–71 Backbone.js dependencies, 2 distributed application design, 6 fetching local copy of, 4 fetching via content delivery networks, 5 fetching with Node’s package manager, 2 philosophy of, 2, 145 Backbone.Model building a data layer, 26 data resolution, 88 DRYer Views and ViewModels, 46 modal view, 125 sorting, 62 wrapping a data store, 101 Backbone.ModelBinder, 39 Backbone.Obscura, 68, 137 Backbone.Router addressing state, 49–55 orchestrating views, 55–60 overview of, 49 Backbone.Sync, 84, 87 Backbone.View basic events, 31 basic rendering, 37 basic view templates, 41 DRYer Views and ViewModels, 46 filtering, 66 handling UI events, 43 modal view, 125 navbar view, 123 parent/child views, 56 rendering a collection, 42 sorting, 62 templates, 74 Backburner, 76 backend-as-a-service providers, 94, 98 bind function, 159 bindAll function, 159 binding, 39 Bluebird library, 103 Bower, 136 Browserify, 10, 29, 136 browsers development console, 15 DOM representation in, 161 packaging modules for, 9 166 | Index security in, 113 (see also authentication) browsing experience mock-up, 19 Brunch, 136 build automation goals of, 77 Grunt, 77 overview of, 135 scaffolding components, 143 tools to improve productivity, 135 Yeoman, 138 C callbacks, 103 Catero, 136 Cavage, Mark, 100 chaining methods, 161 change events, 28 Chaplin framework, 136, 146 child views, 56 className property, 37 click dummy basic CSS for, 25 basic events, 31 basic HTML for, 24 data layer, 26 preparation overview, 24 Cloudflare, 5 Cocoa API, 22 Codepen.io, 5 CoffeeScript, 136 collection helpers, 161 collections filtering, 21, 66 pagination, 68 sorting, 21, 62 transforming, 61 Underscore.js helpers, 158 command line interface (CLI) benefits of, 1 bundling modules from, 10 npm (Node package manager), 2 CommonJS modules benefits of, 8 Browserify, 10 Cartero management system, 136 Express.js and Stitch, 13 require in browsers, 9 comparator function, 62 content delivery network (CDN), 5 controllers, 24, 55 convention-over-configuration, 147 cookies drawbacks of, 115, 118 overview of, 114 session management, 118 user signup, 116 CORS (cross origin resource sharing), 99 createUser method, 116 cross-site request forgery (CSRF), 114 cross-site scripting (XSS), 114 D data binding, 39 building the data layer, 26 controlling access to, 113 (see also authentication) representation with models, 21 transforming with Underscore.js, 158 databases non-relational, 98 NoSQL, 98 relational, 98 wrapping data stores behind an API, 101 debuggers, 15 Decker, Kevin, 145 default properties, 27 dependencies managing with Bower, 136 resolving with main.js file, 141 reusing across projects, 8 Underscore.js, 158–160 Document Object Model (DOM) changing multiple nodes at once, 76 manipulation libraries, 2 node types, 161 statelessness and, 19 DOM nodes attaching/removing event handlers, 162 chaining methods on, 161 operating on directly, 161 preventing event bubbling, 162 selecting with jQuery, 161 types of, 161 DRYer views, 46 E Eastridge, Ryan, 145 ECO (embedded CoffeeScript), 75 event bubbling, 162 event handlers attaching/removing, 162 for UI events, 43 event listeners, 39 events change events, 28 default, 31 handling UI events, 43 sources of, 21, 31 Express.js, 13, 100 extend function, 27, 160 F fetching information asynchronous effects, 92 from hosted backend services, 94 overview of, 83, 87 RESTful web service handling, 84 filtering, 66 Firebase, 94 frameworks benefits of, 145 Chaplin, 146 Giraffe, 146 Junior, 146 Marionette, 146 Rendr, 146 Thorax.js, 146 Function.prototype.bind, 159 functional programming, 158 functions binding context to, 159 get, 28 private, 28 set, 28 sharing across multiple objects, 160 G get function, 28 Giraffe, 146 Grunt, 77 Index | 167 H Handlebars, 76 hashes/hashbangs, 50 Homebrew package manager, 157 HTTP requests basic verbs, 84 cookies, 115 sending from JavaScript, 163 signing, 114 HTTP responses, 102 I index.html, 9 inheritance, 160 isomorphic application design, 97 J JavaScript adding moudles from command line, 143 Ajax, 163 basic abstractions for Backbone.js, 1 debugging, 15 distributed application design, 6 HTTP requests from, 163 jQuery basics of, 160 element selection, 161 event handling, 162 Node.js installation, 157 overview of, 157 promises, 102 Underscore.js benefits of, 158 collections/arrays, 158 functions, 159 objects, 160 utility functions, 160 (see also objects) jQuery Ajax browsing experience mock-up, 19 jQuery API for, 163 basics of, 160 chaining methods, 161 collection helpers, 161 element selection, 161 event handling, 162 168 | Index node wrappers, 161 referencing, 35 JSBin, 5 JSFiddle, 5 JSLint/JSHint, 16 JST (JavaScript Templates), 74 Junior, 146 K key-value pairs data representation with, 21 primary keys, 107 syntax considerations for, 28 L LAMP (Linux-Apache-MySQL-PHP), 98 Layout View, 55 Linux, Node.js installation, 157 M Mac OS Homebrew package manager, 157 Node.js installation, 157 main.js file, 141 Marionette, 146 Mincer, 13 mixin functions, 46 mock-ups APIs, 85 browsing experience, 19 data, 149 wireframes, 19 Mockjax, 149 modal view, 125 model parameter, 29 model-view-controller (MVC) pattern, 22 models (see Backbone models) modules Browserify, 10 bundling from command line, 10 choosing, 8 CommonJS, 8 packaging for browsers, 9 RequireJS, 142 Morell, Jeremy, 68 Munich Cinema example API creation, 100 click dummy preparation basic CSS, 25 basic events, 31 basic HTML, 24 data layer, 26 overview of, 24 current web page, 18 preliminary mock-up, 19 project goals, 18 star rating/voting system, 108 synchronizing state in basic sync and fetch, 87 fetching remote movies, 84 goals of, 83 user interface DRYer views/ViewModels, 46 goals for, 35 handling UI events, 43 interfacing the DOM, 36–43 referencing jQuery, 35 N Navbar view, 123 navigate function, 54 navigation view (navbar), 123 NeXTSTEP operating system, 22 noBackend providers, 94, 98 Node.js installation of, 157 package manager, 2 read-eval-print-loop (REPL), 15 nodes (see DOM nodes) non-relational data stores, 98 npm (Node package manager), 2, 8 O object-relational-mapper (ORM), 98 objects customizing interfaces of, 160 rendering within templates, 160 open-source software, 4 P package managers, 13 pagination, 68 parent views, 56 passwords, 113 (see also authentication) persistence, 101, 108 primary keys, 107 private functions, 28 productivity, improving, 135 (see also workflow automation) promises, 103 proxies, 98 publish-subscribe pattern, 31 pushState(), 50 R React.js, 77 read-eval-print-loop (REPL), 15, 29 relational databases, 98 render function, 37 Rendr, 146 representations in RESTful web services, 85 with models, 21 RequireJS adding modules, 142 benefits of, 140 main.js file, 141 RESTful web services, 84 Restify library, 100 router basics addressing state defining routes, 51 goal of, 49 navigating, 54 preparing, 50 orchestrating views Layout View, 55 parent/child views, 56 overview of, 49 S security, 113 (see also authentication) session management Backbone applications API calls, 118 login dialog, 129 modal view, 125 navbar view, 123 cookies, 118 Index | 169 creating new, 131 logout, 132 set function, 28 signing requests approaches to, 114 benefits of, 114 sorting, 62 Sprockets, 13 state addressing with routers defining routes, 51 goal of, 49 navigating, 54 preparing, 50 authentication and, 131 decoupling from UI benefits of, 22 models and collections, 21 MVC pattern, 22 need for, 19 views, 22 synchronizing basic sync and fetch, 87 fetching remote information, 84 overview of, 83 statelessness, 19, 84 Stitch, 13 T tagName property, 37 template property, 41, 75 templates embedded CoffeeScript, 75 Handlebars, 76 JavaScript Templates, 74 overview of, 73 Thorax.js benefits of, 145 getting started application initialization, 150 build tasks, 147 installation/setup of, 147 mock data preparation, 149 overview of, 146 rendering advanced views, 154 Router setup, 152 Thorax.Collection, 152 TodoMVC demo, 24 tokens, access, 114 170 | Index U Ubuntu, Node.js installation, 157 Underscore.js benefits of, 158 collections/arrays, 158 functions, 159 objects, 160 utility functions, 160 user interface decoupling from state benefits of, 22 models and collections, 21 MVC pattern, 22 need for, 19 views, 22 DRYer views/ViewModels, 46 goals for, 35 handling UI events, 43 interfacing the DOM basic rendering, 37 basic view templates, 41 bindings to data changes, 39 rendering a collection, 42 strategy overview, 36 referencing jQuery, 35 V ViewModels, 46 views advanced view templates, 73 Backbone views, 22 data display management with, 23 DRYer view/ViewModels, 46 Layout View, 55 modal view, 125 MVC pattern, 22 navbar view, 123 parent/child views, 56 updating immediately, 39 welcome view, 59 vulnerabilities cross-site request forgery (CSRF), 114 cross-site scripting (XSS), 114 W Walmart’s shopping cart, 147 welcome view, 59 Windows, Node.js installation, 157 wireframes benefits of, 19 creating, 18 workflow, automation of (see build automation) X benefits of, 136, 138 installation of, 138 running, 139 Z Zepto library, 2, 160 XMLHttpRequest object, 163 Y Yeoman application directory, 140 Index | 171 About the Author Before discovering software development for web applications with Java and Ruby in 2008, Patrick Mulder mainly worked as a software engineer on measurement equip‐ ment and electronic devices.

Send email to index@oreilly.com. 165 Backbone.Collection, sorting/filtering models with, 61–71 Backbone.js dependencies, 2 distributed application design, 6 fetching local copy of, 4 fetching via content delivery networks, 5 fetching with Node’s package manager, 2 philosophy of, 2, 145 Backbone.Model building a data layer, 26 data resolution, 88 DRYer Views and ViewModels, 46 modal view, 125 sorting, 62 wrapping a data store, 101 Backbone.ModelBinder, 39 Backbone.Obscura, 68, 137 Backbone.Router addressing state, 49–55 orchestrating views, 55–60 overview of, 49 Backbone.Sync, 84, 87 Backbone.View basic events, 31 basic rendering, 37 basic view templates, 41 DRYer Views and ViewModels, 46 filtering, 66 handling UI events, 43 modal view, 125 navbar view, 123 parent/child views, 56 rendering a collection, 42 sorting, 62 templates, 74 Backburner, 76 backend-as-a-service providers, 94, 98 bind function, 159 bindAll function, 159 binding, 39 Bluebird library, 103 Bower, 136 Browserify, 10, 29, 136 browsers development console, 15 DOM representation in, 161 packaging modules for, 9 166 | Index security in, 113 (see also authentication) browsing experience mock-up, 19 Brunch, 136 build automation goals of, 77 Grunt, 77 overview of, 135 scaffolding components, 143 tools to improve productivity, 135 Yeoman, 138 C callbacks, 103 Catero, 136 Cavage, Mark, 100 chaining methods, 161 change events, 28 Chaplin framework, 136, 146 child views, 56 className property, 37 click dummy basic CSS for, 25 basic events, 31 basic HTML for, 24 data layer, 26 preparation overview, 24 Cloudflare, 5 Cocoa API, 22 Codepen.io, 5 CoffeeScript, 136 collection helpers, 161 collections filtering, 21, 66 pagination, 68 sorting, 21, 62 transforming, 61 Underscore.js helpers, 158 command line interface (CLI) benefits of, 1 bundling modules from, 10 npm (Node package manager), 2 CommonJS modules benefits of, 8 Browserify, 10 Cartero management system, 136 Express.js and Stitch, 13 require in browsers, 9 comparator function, 62 content delivery network (CDN), 5 controllers, 24, 55 convention-over-configuration, 147 cookies drawbacks of, 115, 118 overview of, 114 session management, 118 user signup, 116 CORS (cross origin resource sharing), 99 createUser method, 116 cross-site request forgery (CSRF), 114 cross-site scripting (XSS), 114 D data binding, 39 building the data layer, 26 controlling access to, 113 (see also authentication) representation with models, 21 transforming with Underscore.js, 158 databases non-relational, 98 NoSQL, 98 relational, 98 wrapping data stores behind an API, 101 debuggers, 15 Decker, Kevin, 145 default properties, 27 dependencies managing with Bower, 136 resolving with main.js file, 141 reusing across projects, 8 Underscore.js, 158–160 Document Object Model (DOM) changing multiple nodes at once, 76 manipulation libraries, 2 node types, 161 statelessness and, 19 DOM nodes attaching/removing event handlers, 162 chaining methods on, 161 operating on directly, 161 preventing event bubbling, 162 selecting with jQuery, 161 types of, 161 DRYer views, 46 E Eastridge, Ryan, 145 ECO (embedded CoffeeScript), 75 event bubbling, 162 event handlers attaching/removing, 162 for UI events, 43 event listeners, 39 events change events, 28 default, 31 handling UI events, 43 sources of, 21, 31 Express.js, 13, 100 extend function, 27, 160 F fetching information asynchronous effects, 92 from hosted backend services, 94 overview of, 83, 87 RESTful web service handling, 84 filtering, 66 Firebase, 94 frameworks benefits of, 145 Chaplin, 146 Giraffe, 146 Junior, 146 Marionette, 146 Rendr, 146 Thorax.js, 146 Function.prototype.bind, 159 functional programming, 158 functions binding context to, 159 get, 28 private, 28 set, 28 sharing across multiple objects, 160 G get function, 28 Giraffe, 146 Grunt, 77 Index | 167 H Handlebars, 76 hashes/hashbangs, 50 Homebrew package manager, 157 HTTP requests basic verbs, 84 cookies, 115 sending from JavaScript, 163 signing, 114 HTTP responses, 102 I index.html, 9 inheritance, 160 isomorphic application design, 97 J JavaScript adding moudles from command line, 143 Ajax, 163 basic abstractions for Backbone.js, 1 debugging, 15 distributed application design, 6 HTTP requests from, 163 jQuery basics of, 160 element selection, 161 event handling, 162 Node.js installation, 157 overview of, 157 promises, 102 Underscore.js benefits of, 158 collections/arrays, 158 functions, 159 objects, 160 utility functions, 160 (see also objects) jQuery Ajax browsing experience mock-up, 19 jQuery API for, 163 basics of, 160 chaining methods, 161 collection helpers, 161 element selection, 161 event handling, 162 168 | Index node wrappers, 161 referencing, 35 JSBin, 5 JSFiddle, 5 JSLint/JSHint, 16 JST (JavaScript Templates), 74 Junior, 146 K key-value pairs data representation with, 21 primary keys, 107 syntax considerations for, 28 L LAMP (Linux-Apache-MySQL-PHP), 98 Layout View, 55 Linux, Node.js installation, 157 M Mac OS Homebrew package manager, 157 Node.js installation, 157 main.js file, 141 Marionette, 146 Mincer, 13 mixin functions, 46 mock-ups APIs, 85 browsing experience, 19 data, 149 wireframes, 19 Mockjax, 149 modal view, 125 model parameter, 29 model-view-controller (MVC) pattern, 22 models (see Backbone models) modules Browserify, 10 bundling from command line, 10 choosing, 8 CommonJS, 8 packaging for browsers, 9 RequireJS, 142 Morell, Jeremy, 68 Munich Cinema example API creation, 100 click dummy preparation basic CSS, 25 basic events, 31 basic HTML, 24 data layer, 26 overview of, 24 current web page, 18 preliminary mock-up, 19 project goals, 18 star rating/voting system, 108 synchronizing state in basic sync and fetch, 87 fetching remote movies, 84 goals of, 83 user interface DRYer views/ViewModels, 46 goals for, 35 handling UI events, 43 interfacing the DOM, 36–43 referencing jQuery, 35 N Navbar view, 123 navigate function, 54 navigation view (navbar), 123 NeXTSTEP operating system, 22 noBackend providers, 94, 98 Node.js installation of, 157 package manager, 2 read-eval-print-loop (REPL), 15 nodes (see DOM nodes) non-relational data stores, 98 npm (Node package manager), 2, 8 O object-relational-mapper (ORM), 98 objects customizing interfaces of, 160 rendering within templates, 160 open-source software, 4 P package managers, 13 pagination, 68 parent views, 56 passwords, 113 (see also authentication) persistence, 101, 108 primary keys, 107 private functions, 28 productivity, improving, 135 (see also workflow automation) promises, 103 proxies, 98 publish-subscribe pattern, 31 pushState(), 50 R React.js, 77 read-eval-print-loop (REPL), 15, 29 relational databases, 98 render function, 37 Rendr, 146 representations in RESTful web services, 85 with models, 21 RequireJS adding modules, 142 benefits of, 140 main.js file, 141 RESTful web services, 84 Restify library, 100 router basics addressing state defining routes, 51 goal of, 49 navigating, 54 preparing, 50 orchestrating views Layout View, 55 parent/child views, 56 overview of, 49 S security, 113 (see also authentication) session management Backbone applications API calls, 118 login dialog, 129 modal view, 125 navbar view, 123 cookies, 118 Index | 169 creating new, 131 logout, 132 set function, 28 signing requests approaches to, 114 benefits of, 114 sorting, 62 Sprockets, 13 state addressing with routers defining routes, 51 goal of, 49 navigating, 54 preparing, 50 authentication and, 131 decoupling from UI benefits of, 22 models and collections, 21 MVC pattern, 22 need for, 19 views, 22 synchronizing basic sync and fetch, 87 fetching remote information, 84 overview of, 83 statelessness, 19, 84 Stitch, 13 T tagName property, 37 template property, 41, 75 templates embedded CoffeeScript, 75 Handlebars, 76 JavaScript Templates, 74 overview of, 73 Thorax.js benefits of, 145 getting started application initialization, 150 build tasks, 147 installation/setup of, 147 mock data preparation, 149 overview of, 146 rendering advanced views, 154 Router setup, 152 Thorax.Collection, 152 TodoMVC demo, 24 tokens, access, 114 170 | Index U Ubuntu, Node.js installation, 157 Underscore.js benefits of, 158 collections/arrays, 158 functions, 159 objects, 160 utility functions, 160 user interface decoupling from state benefits of, 22 models and collections, 21 MVC pattern, 22 need for, 19 views, 22 DRYer views/ViewModels, 46 goals for, 35 handling UI events, 43 interfacing the DOM basic rendering, 37 basic view templates, 41 bindings to data changes, 39 rendering a collection, 42 strategy overview, 36 referencing jQuery, 35 V ViewModels, 46 views advanced view templates, 73 Backbone views, 22 data display management with, 23 DRYer view/ViewModels, 46 Layout View, 55 modal view, 125 MVC pattern, 22 navbar view, 123 parent/child views, 56 updating immediately, 39 welcome view, 59 vulnerabilities cross-site request forgery (CSRF), 114 cross-site scripting (XSS), 114 W Walmart’s shopping cart, 147 welcome view, 59 Windows, Node.js installation, 157 wireframes benefits of, 19 creating, 18 workflow, automation of (see build automation) X benefits of, 136, 138 installation of, 138 running, 139 Z Zepto library, 2, 160 XMLHttpRequest object, 163 Y Yeoman application directory, 140 Index | 171 About the Author Before discovering software development for web applications with Java and Ruby in 2008, Patrick Mulder mainly worked as a software engineer on measurement equip‐ ment and electronic devices.


pages: 323 words: 65,306

Programming in CoffeeScript by Mark Bates

don't repeat yourself, en.wikipedia.org, MVC pattern, node package manager, Ruby on Rails, single page application, web application

To do this we are going to use the most popular Node framework out there, Express.2 Express is easy to install and get up and running fairly quickly, and it has a vibrant development community, which makes it a great choice for the task at hand. In a nice, fresh directory, let’s create a new file, app.coffee, that will be the starting point for our Express backend. Right now, let’s just leave that file blank while we install Express. Express ships as an NPM,3 Node Package Manager, module. We briefly mentioned NPM in Chapter 9, “Intro to Node.js.” NPM modules are bundles of code that are packaged up and distributed and can then be installed, included, and required into Node applications. If you have Node installed, you should already have NPM installed. Installing Express is a simple one liner: > npm install express You should see output similar to this: express@2.5.2 .

I really do love it and use it all the time. 5. http://documentcloud.github.com/underscore 6. http://zeptojs.com 7. https://github.com/codebrew/backbone-rails 8. http://www.mongodb.org/ 9. https://github.com/markbates/Programming-In-CoffeeScript Index @ alias, 51–52 => (fat arrow), 154–156 \ (back slashes), 5 / (forward slashes), 76 A adding compilers to browsers, 6–7 form to client-side todo list application, 242–247 jQuery to client-side todo list application, 240–241 views to todo list application, 268–273 aliases, 46–47 @ alias, 51–52 and alias, 49–50 Boolean aliases, 50–51 not alias, 48–49 or alias, 49–50 and alias, 49–50 anonymous wrapper function, 20–22 APIs, writing todo API, 225–226 app server building with Node.js, 199–213 testing with Node.js, 214–215 arguments, 70–72 default arguments, 72–75 splats, 75–79 arithmetic operators, 33–35 arrays, 81–90 destructing assignment, 86–90 iterating, 105–106 slicing, 92–94 swapping assignment, 85–86 testing inclusion, 83–84 values injecting, 95–96 replacing, 94–95 Ashkenas, Jeremy, 255 assignment operators, 35–39 asynchronous programming, 151–154 attributes, retrieving from objects, 101–103 B back slashes (\), 5 Backbone, 255–256 configuring for todo list application, 256–259 todo model, writing, 256–259 todos creating, 265–268 listing with view, 263–265 bare flag, 9–10 beforeEach function, 181–187 binding, 151–158 block comments, 30 Boolean aliases, 50–51 Bootstrap, building client-side todo list application, 237–240 browsers, in-browser compilation, 6–7 build task (Cake), 167 building objects, 96–101 todo list application client-side, 237–252 controller, cleaning up, 232–236 Express, setting up, 218–222 MongoDB, setting up, 222–225 server-side, 217 todo API, writing, 225–226 by keyword, 106–107 C Cake, 161 tasks invoking, 167–169 options, 163–167 running, 163 writing, 162–163 Cakefiles, 161 calling functions, 68–70 classes defining, 123–124 extending, 137–145 inheritance, 137–145 scope, 127–137 class-level functions, 145–150 clean task (Cake), 167 cleaning up todo list application controller, 232–236 client-side todo list application, building, 237–252 closing REPL, 5 code, not repeating, 68 coffee command, 8–9 CoffeeScript, declaring variables, 19–20 collections arrays destructing assignment, 86–90 injecting values, 95–96 iterating, 105–106 replacing values, 94–95 slicing, 92–94 swapping assignment, 85–86 testing inclusion, 83–84 ranges, reverse ranges, 91–92 command-line compilation, 7–8 comments, 29–30 block comments, 30 inline comments, 29–30 comparison operators, 39–42 compile flag, 7–8 compiling command-line compilation, 7–8 in-browser compilation, 6–7 comprehensions, 116–118 concatenation, forward slashes (/), 76 conditional statements if statement, 53–54 if/else if statement, 56–58 if/else statement, 54–56 inline conditionals, 60 switch case statements, 60–63 unless statement, 58–60 configuring Backbone for todo list application, 256–259 Jasmine, 172–175 constructor function, 126–127 creating objects, 96–101 custom matchers (Jasmine), defining, 187–190 D declaring variables in CoffeeScript, 19–20 in JavaScript, 18–19 default arguments, 72–75 defining Cake tasks, 162–163 classes, 123–124 functions, 68–70 arguments, 70–72 default arguments, 72–75 parentheses, 72 matchers (Jasmine), 187–190 regular expressions, 31 deleting models from views (todo list application), 273–274 todos in client-side todo list application, 252 “describe” block (Jasmine), writing, 175 destructing assignment, 86–90 do keyword, 119–120 dot notation, 101 E executing CoffeeScript files, 11 existential operator, 43–46 Express, building todo list application, 218–222 extended regular expressions, 31 extending classes, 137–145 F fat arrow (=>), 154–156 flags bare flag, 9–10 compile flag, 7–8 output flag, 9 print flag, 10 watch flag, 10–11 for loops by keyword, 106–107 when keyword, 107, 109–110 form, adding to client-side todo list application, 242–247 function keyword, 16 functions, 65–68 anonymous wrapper function, 20–22 arguments, 70–72 default arguments, 72–75 splats, 75–79 beforeEach, 181–187 binding, 151–158 class-level, 145–150 constructor, 126–127 defining, 68–70, 125–126 overriding, 142–145 prototype functions, 110, 150–151 G-H Hello World program, Node.js, 195–197 heredocs, 28–29 HTML files in-browser compilation, 6–7 I if statement, 53–54 if/else if statement, 56–58 if/else statement, 54–56 in-browser compilation, 6–7 inheritance, 137–145 injecting array values, 95–96 inline comments, 29–30 inline conditionals, 60 installing Jasmine, 172 Node.js, 194–195 interpolation, string interpolation, 23–25 iterating arrays, 105–106 J-K Jasmine “describe” block, writing, 175 installing, 172 matchers, defining, 187–190 setting up, 172–175 testing with, 175–176 beforeEach function, 181–187 unit testing, 176–181 JavaScript Backbone, 255–256 todo model, writing, 256–259 todos, listing with a view, 263–265 Node.js, 193–194 app server, building, 199–213 app server, testing, 214–215 Hello World program, 195–197 installing, 194–195 streaming APIs, writing, 197–199 variables, declaring, 18–19 jQuery, adding to client-side todo list application, 240–241 keywords, var, 19 L listing existing todos in todo list application, 247–248 literal strings, 25–28 long options, 163 loops comprehensions, 116–118 do keyword, 119–120 for loops by keyword, 106–107 when keyword, 107, 109–110 until loops, 114–115 while loops, 113–114 M-N MongoDB, setting up, 222–225 Mongoose, finding todos in todo list application, 227–228 new keyword, 124 Node.js, 193–194 app server building, 199–213 testing, 214–215 Hello World program, 195–197 installing, 194–195 streaming APIs, writing, 197–199 NPM (Node Package Management), 193 Express, setting up, 218–222 O objects attributes, retrieving, 101–103 building, 96–101 destructing assignment, 103–105 iterating, 108–113 operators aliases, 46–47 @ alias, 51–52 and alias, 49–50 Boolean aliases, 50–51 not alias, 48–49 or alias, 49–50 arithmetic operators, 33–35 assignment operators, 35–39 comparison operators, 39–42 existential operator, 43–46 string operators, 42–43 options for Cake tasks, 163–167 or alias, 49–50 output flag, 9 overriding functions, 142–145 P parentheses, 16–17 comprehensions, 117 functions, calling, 72 print flag, 10 prototype function, 110 prototype functions, 150–151 Q-R querying todo list application, 227–228 quitting REPL, 5 ranges, 90–96 reverse ranges, 91–92 regular expressions, extended regular expressions, 31 REPL, 3–5 \ (back slashes), 5 Node.js, 194 quitting, 5 replacing array values, 94–95 retrieving attributes from objects, 101–103 reverse ranges, 91–92 running Cake tasks, 163 S scope in classes, 127–137 servers (Node.js), creating, 195–197 server-side, building todo list application, 217 setting up Jasmine, 172–175 short options, 163 significant whitespace, 14–16 slicing arrays, 92–94 splats, 75–79 streaming APIs, writing with Node.js, 197–199 string interpolation, 23–25 string operators, 42–43 strings heredocs, 28–29 literal strings, 25–28 switch case statements, 60–63 synchronous programming, 151 syntax function keyword, 16 parentheses, 16–17 ranges, 90 significant whitespace, 14–16 T tasks Cake invoking, 167–169 options, 163–167 running, 163 writing, 162–163 TDD (test-driven development), 171 terminating REPL, 5 testing with Jasmine, 175–176 beforeEach function, 181–187 matchers, defining, 187–190 TDD, 171 unit testing, 176–181 testing inclusion, Node.js app server, 214–215 todo list application Backbone configuring, 256–259 todos, creating, 265–268 todos, listing with a view, 263–265 client-side building, 237–252 exisiting todos, listing, 247–248 form, creating, 242–247 jQuery, adding, 240–241 todos, deleting, 252 todos, updating, 248–251 controller, cleaning up, 232–236 server-side building, 217 todo API, writing, 225–226 todos creating, 228–230 finding, 227–228 updating, 230–232 views adding, 268–273 deleting models from, 273–274 todo list application, building Express, setting up, 218–222 MongoDB, setting up, 222–225 Twitter Bootstrap todo list application client-side, building, 237–240 U unit testing with Jasmine, 176–181 unless statement, 58–60 until loops, 114–115 updating todo list application, 230–232 todos in client-side todo list application, 248–251 V var keyword, 19 variables, declaring in CoffeeScript, 19–20 in JavaScript, 18–19 views adding to todo list application, 268–273 models, deleting from (todo list application), 273–274 W-X-Y-Z watch flag, 10–11 when keyword, 109–110 while loops, 113–114 writing Cake tasks, 162–163 “describe” block (Jasmine), 175 todo API, 225–226 todo model with Backbone, 256–259 Footnotes Acknowledgments 1 Many at my publishing house thought that my acknowledgments section, as well as other parts of this book, were a bit risqué, so the original has been edited down to what you see here.


pages: 59 words: 12,801

The Little Book on CoffeeScript by Alex MacCaw

duck typing, Firefox, MVC pattern, node package manager, web application, Y2K

In fact, you can use the browser-based CoffeeScript compiler yourself, by including this script in a page, marking up any CoffeeScript script tags with the correct type: <script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js" type="text/javascript" charset="utf-8"></script> <script type="text/coffeescript"> # Some CoffeeScript </script> Obviously, in production, you don’t want to be interpreting CoffeeScript at runtime, as it’ll slow things up for your clients. Instead, CoffeeScript offers a Node.js compiler to pre-process CoffeeScript files. To install it, first make sure you have a working copy of the latest stable version of Node.js and npm (the Node Package Manager). You can then install CoffeeScript with npm: npm install -g coffee-script The -g flag is important, as it tells npm to install the coffee-script package globally, rather than locally. Without it, you won’t get the coffee executable. If you execute the coffee executable without any command line options, it’ll give you the CoffeeScript console, which you can use to quickly execute CoffeeScript statements.


pages: 550 words: 84,515

Vue.js 2 Cookbook by Andrea Passaglia

bitcoin, business logic, cognitive load, functional programming, Kickstarter, Large Hadron Collider, loose coupling, MVC pattern, node package manager, Silicon Valley, single page application, web application, WebSocket

There's more Reacting to events such as clicks and keystrokes Getting Ready How to do it... How it works... Two-way data binding There's more Choosing a development environment How to do it... Just the browser Adding dependencies with just the browser TextEditor Adding dependencies with a TextEditor Node package manager (npm) Adding dependencies with npm IDE Wrap up Formatting your text with filters Getting Ready How to do it... How it works... Debugging your application with mustaches (for example, a JSON filter) How to do it... How it works... X-raying your application with Vue developer tools Getting Ready How to do it...

If we wanted to add moment.js, we look for the library in the same way as explained before and we add the following snippet to our page: <script src="https://somecdn.com/moment.js/X.X.X/moment.js "></script> Please note that you have to paste the link you found instead of the fake one mentioned in the preceding snippet. Node package manager (npm) The canonical way to work with Vue projects, and the one officially supported by the Vue community, involves the use of npm and in particular an npm package named vue-cli. If you are not familiar with npm, put it on your list of things to do, especially if you plan to develop with JavaScript extensively.


Large Scale Apps with Vue 3 and TypeScript by Damiano Fusco

continuous integration, en.wikipedia.org, node package manager, place-making, single source of truth, source of truth

I will highlight most terms or names in bold, rather than define different fonts/styles depending on whether a term is code, or a directory name or something else. Prerequisites This book assumes that you are familiar with the terminal (command prompt on Windows), have already worked with the Node.js and NPM (Node Package Manager), know how to install packages, and are familiar with the package.json file. It also assumes you are familiar with JavaScript, HTML, CSS and in particular with HTML DOM elements properties and events. It will also help if you have some preliminary knowledge of TypeScript1 as we won’t get into details about the language itself or all of its features but mostly illustrate how to enforce type checking at development time with it.


pages: 193 words: 36,189

Html5 Boilerplate Web Development by Divya Manian

en.wikipedia.org, Firefox, Google Chrome, node package manager, pull request, Ruby on Rails, search engine result page

The configuration file assumes you are using the Express/Connect framework for managing resource requests for your app. In your server-side app code, you can use the following to start the server: var h5bp = require('h5bp'); var app = express.createServer(); app.use(h5bp.server()); app.listen(3000); This requires you to install the h5bp package using Node Package Manager (NPM) and the express package using the same. The h5bp package has a slew of configurations that will be used when the server is started. If you wish to use only some specific configurations, you can pass them in as options to the server function, as shown in the following code snippet: app.use(h5bp.server({ server: true, setContentType: true, removeEtag: true }); Google App Engine Some websites are also served from Google App Engine (http://code.google.com/appengine/), which requires your website's backend to be written in Java, Python, or Go.


pages: 196 words: 58,122

AngularJS by Brad Green, Shyam Seshadri

business logic, combinatorial explosion, continuous integration, Firefox, Google Chrome, Kickstarter, MVC pattern, node package manager, single page application, systems thinking, web application, WebSocket

We at AngularJS have found this to be true, and the entire AngularJS codebase has been developed using TDD. For an uncompiled, dynamic language like JavaScript, we strongly believe that having a good set of unit tests will reduce headaches in the future! So how do we get this awesomeness that is Karma? Well, first ensure that NodeJS is installed on your machine. This comes with NPM (Node Package Manager), which makes it easy to manage and install the thousands of libraries available for NodeJS. Once you have NodeJS and NPM installed, installing Karma is as easy as running: sudo npm install -g karma There you go. You are ready to start Karmaing (I just made that up, please don’t go about using it in real life) in three easy steps!


Mastering Blockchain, Second Edition by Imran Bashir

3D printing, altcoin, augmented reality, autonomous vehicles, bitcoin, blockchain, business logic, business process, carbon footprint, centralized clearinghouse, cloud computing, connected car, cryptocurrency, data acquisition, Debian, disintermediation, disruptive innovation, distributed ledger, Dogecoin, domain-specific language, en.wikipedia.org, Ethereum, ethereum blockchain, fault tolerance, fiat currency, Firefox, full stack developer, general-purpose programming language, gravity well, information security, initial coin offering, interest rate swap, Internet of things, litecoin, loose coupling, machine readable, MITM: man-in-the-middle, MVC pattern, Network effects, new economy, node package manager, Oculus Rift, peer-to-peer, platform as a service, prediction markets, QR code, RAND corporation, Real Time Gross Settlement, reversible computing, RFC: Request For Comment, RFID, ride hailing / ride sharing, Satoshi Nakamoto, seminal paper, single page application, smart cities, smart contracts, smart grid, smart meter, supply-chain management, transaction costs, Turing complete, Turing machine, Vitalik Buterin, web application, x509 certificate

We will discuss various constructs of Solidity language in detail, which is currently the most popular development language for smart contract development on Ethereum. In this chapter we will cover the following topics: Development tools, IDEs, and clients Remix Ganache EthereumJS TestRPC MetaMask Truffle Prerequisites Node Node Package Manager (NPM) Other tools and utilities There are a number of tools available for Ethereum development. The following diagram shows the taxonomy of various development tools, clients, IDEs, and development frameworks for Ethereum: Taxonomy of Ethereum development ecosystem components The preceding taxonomy does not include all frameworks and tools that are out there for development on Ethereum.

Installation Before installation, it is assumed that node is available, which can be queried as shown here. If the node is not available, then the installation of node is required first in order to install truffle: $ node -version v7.2.1 The installation of truffle is very simple and can be done using the following command via Node Package Manager (npm): $ sudo npm install -g truffle This will take a few minutes; once it is installed, the truffle command can be used to display help information and verify that it is installed correctly: $ sudo npm install -g truffle Password: /us/local/bin/truffle -> /usr/local/lib/node_modules/truffle/build/cli.bundled.js /usr/local/lib └── truffle@4.0.1 Type truffle at Terminal to display usage help: $ truffle This will display the following output: Truffle help Alternatively, the repository is available at https://github.com/ConsenSys/truffle, which can be cloned locally to install truffle.


pages: 739 words: 174,990

The TypeScript Workshop: A Practical Guide to Confident, Effective TypeScript Programming by Ben Grynhaus, Jordan Hudgens, Rayon Hunte, Matthew Thomas Morgan, Wekoslav Stefanovski

Ada Lovelace, Albert Einstein, business logic, Charles Babbage, create, read, update, delete, don't repeat yourself, Donald Knuth, fault tolerance, Firefox, full stack developer, functional programming, Google Chrome, Hacker News, higher-order functions, inventory management, Kickstarter, loose coupling, node package manager, performance metric, QR code, Ruby on Rails, SQL injection, type inference, web application, WebSocket

Jordan Hudgens is a full-stack developer and the founder of DevCamp and the Bottega Code School. As a developer over the past 15 years, he specializes in Ruby on Rails, React, Vue.js, and TypeScript with a focus on API development. He has built applications for a wide variety of organizations, including Eventbrite and Quip. He has published and maintains multiple open source Node Package Manager (npm) modules that help individuals automate the development process for JavaScript and TypeScript applications. Additionally, he has published over 30 courses, taught 42,000 students globally, and written several programming books. Rayon Hunte has been working with Angular and TypeScript for more than 3 years.

Import, Export, and Require Very small programs, such as the kind often found in books on programming, can work just fine with all the code in a single file. Most of the time, applications will be made up of multiple files, often referred to as modules. Some modules may be dependencies installed from Node Package Manager (npm) and some may be modules you or your team have written. When you look at other projects, you may see the keywords import, export, module, and require used to link different modules together. import and require both serve the same purpose. They allow you to use another module in the module (file) you are currently working in. export and module are the opposite.


pages: 420 words: 79,867

Developing Backbone.js Applications by Addy Osmani

Airbnb, anti-pattern, business logic, create, read, update, delete, don't repeat yourself, Firefox, full text search, Google Chrome, Khan Academy, Kickstarter, loose coupling, MVC pattern, node package manager, pull request, Ruby on Rails, side project, single page application, web application

If you are more comfortable in setting up a REST server in another language, this is the API you need to conform to: url HTTP Method Operation /api/books GET Get an array of all books /api/books/:id GET Get the book with id of :id /api/books POST Add a new book and return the book with an id attribute added /api/books/:id PUT Update the book with id of :id /api/books/:id DELETE Delete the book with id of :id The outline for this section looks like this: Install node.js, npm, and MongoDB Install node modules Create a simple web server Connect to the database Create the REST API Install node.js, npm, and MongoDB Download and install node.js from nodejs.org. The node package manager (npm) will be installed as well. Download, install, and run MongoDB from mongodb.org (you need Mongo to be running to store data in a Mongo database). There are detailed installation guides on the website. Install node modules Create a file called package.json in the root of your project.


pages: 1,136 words: 73,489

Working in Public: The Making and Maintenance of Open Source Software by Nadia Eghbal

Amazon Web Services, Apollo 11, barriers to entry, Benevolent Dictator For Life (BDFL), Big Tech, bitcoin, Clayton Christensen, cloud computing, commoditize, commons-based peer production, context collapse, continuous integration, crowdsourcing, cryptocurrency, David Heinemeier Hansson, death of newspapers, Debian, disruptive innovation, Dunbar number, en.wikipedia.org, eternal september, Ethereum, Firefox, Free Software Foundation, Guido van Rossum, Hacker Ethic, Hacker News, Induced demand, informal economy, information security, Jane Jacobs, Jean Tirole, Kevin Kelly, Kickstarter, Kubernetes, leftpad, Mark Zuckerberg, Menlo Park, Neal Stephenson, Network effects, node package manager, Norbert Wiener, pirate software, pull request, RFC: Request For Comment, Richard Stallman, Ronald Coase, Ruby on Rails, side project, Silicon Valley, Snapchat, social graph, software as a service, Steve Jobs, Steve Wozniak, Steven Levy, Stewart Brand, tacit knowledge, the Cathedral and the Bazaar, The Death and Life of Great American Cities, The Nature of the Firm, TikTok, Tragedy of the Commons, transaction costs, two-sided market, urban planning, web application, wikimedia commons, Yochai Benkler, Zimmermann PGP

But just as tweets are easy to read and retweet without context as to who wrote them, code is easy to copy-paste without knowing, or caring, where it came from. The npm ecosystem—which, according to its parent company, makes up an estimated 97% of the code in modern web applications today—offers some clues to the future.8 Npm, which stands for Node Package Manager, is the platform commonly used by JavaScript developers to install and manage packages, or libraries. (Libraries are prewritten bits of code that other developers can use, instead of having to write the same code from scratch. The ability to legally reuse other people’s code is what allows software developers to work more quickly and efficiently today.)


pages: 713 words: 93,944

Seven Databases in Seven Weeks: A Guide to Modern Databases and the NoSQL Movement by Eric Redmond, Jim Wilson, Jim R. Wilson

AGPL, Amazon Web Services, business logic, create, read, update, delete, data is the new oil, database schema, Debian, domain-specific language, en.wikipedia.org, fault tolerance, full text search, general-purpose programming language, Kickstarter, Large Hadron Collider, linked data, MVC pattern, natural language processing, node package manager, random walk, recommendation engine, Ruby on Rails, seminal paper, Skype, social graph, sparse data, web application

Adding single members directly to CouchDB for each line in the file can cause update thrashing, where two band member lines attempt to create/update the same band document at the same time, forcing the system to reinsert when one of them fails CouchDB’s version check. The catch with this strategy is that you’re limited to the constraints of Redis to hold an entire dataset in RAM—though this limit could be overcome by the simple consistent-hashing cluster we saw on Day 2. With our data file in hand, ensure you have Node.js installed as well as the Node Package Manager (npm). Once that’s all done, we need to install three NPM projects: redis, csv, and hiredis (the optional Redis C-driver we learned about yesterday that can greatly speed up Redis interactions). ​​$ npm install hiredis redis csv​​ Then, check that your Redis server is running on the default port 6379, or alter each script’s createClient function to point to your Redis port.


pages: 419 words: 102,488

Chaos Engineering: System Resiliency in Practice by Casey Rosenthal, Nora Jones

Amazon Web Services, Asilomar, autonomous vehicles, barriers to entry, blockchain, business continuity plan, business intelligence, business logic, business process, cloud computing, cognitive load, complexity theory, continuous integration, cyber-physical system, database schema, DevOps, fail fast, fault tolerance, hindsight bias, human-factors engineering, information security, Kanban, Kubernetes, leftpad, linear programming, loose coupling, microservices, MITM: man-in-the-middle, no silver bullet, node package manager, operational security, OSI model, pull request, ransomware, risk tolerance, scientific management, Silicon Valley, six sigma, Skype, software as a service, statistical model, systems thinking, the scientific method, value engineering, WebSocket

., Site Reliability Engineering (Sebastopol, CA: O’Reilly, 2016), Chapter 28. 2 This intriguing behavioral tendency is also exhibited in real-life physical emergencies such as building fires: see Lea Winerman, “Fighting Fire with Psychology,” APA Monitor on Psychology, Vol. 35, No. 8 (Sept. 2004). 3 For a great read on this topic, see Ben Treynor et al., “The Calculus of Service Availability,” Communications of the ACM, Vol. 60, No. 9 (Sept. 2017). 4 One notorious public example was the removal of the left-pad package from the Node Package Manager repository (www.npmjs.com) in March 2016, which caused the builds of uncountable JavaScript projects around the globe to stop working. 5 Lottery factor is a metaphor of the risk resulting from information and capabilities not being shared among team members, as exemplified by a team member winning the lottery and quitting without notice.


pages: 960 words: 125,049

Mastering Ethereum: Building Smart Contracts and DApps by Andreas M. Antonopoulos, Gavin Wood Ph. D.

air gap, Amazon Web Services, bitcoin, blockchain, business logic, continuous integration, cryptocurrency, Debian, digital divide, Dogecoin, domain-specific language, don't repeat yourself, Edward Snowden, en.wikipedia.org, Ethereum, ethereum blockchain, fault tolerance, fiat currency, Firefox, functional programming, Google Chrome, information security, initial coin offering, intangible asset, Internet of things, litecoin, machine readable, move fast and break things, node package manager, non-fungible token, peer-to-peer, Ponzi scheme, prediction markets, pull request, QR code, Ruby on Rails, Satoshi Nakamoto, sealed-bid auction, sharing economy, side project, smart contracts, transaction costs, Turing complete, Turing machine, Vickrey auction, Vitalik Buterin, web application, WebSocket

Truffle GitHub: https://github.com/trufflesuite/truffle Website: https://truffleframework.com Documentation: https://truffleframework.com/docs Truffle Boxes: http://truffleframework.com/boxes/ npm package repository: https://www.npmjs.com/package/truffle Installing the Truffle framework The Truffle framework comprises several Node.js packages. Before you install truffle, you need to have an up-to-date and working installation of Node.js and the Node Package Manager (npm). The recommended way to install Node.js and npm is to use the Node Version Manager (nvm). Once you install nvm, it will handle all the dependencies and updates for you. Follow the instructions found at http://nvm.sh. Once nvm is installed on your operating system, installing Node.js is simple.