Event Driven Programming A programming paradigm in which the flow of the program is determined by events such as user actions (mouse clicks, key presses) or messages from other programs. Node Event Loop • Node provides the event loop as part of the language. • With Node, there is no call to start the loop. • The loop starts and doesn't end until the last callback is complete.
• Event loop is run under a single thread therefore sleep() makes everything halt. Callback Style Programming • Event loops result in callback-style programming where you break apart a program into its underlying data flow. • In other words, you end up splitting your program into smaller and smaller chunks until each chunk is mapped to operation with data. So that you don't freeze the event loop on long-running operations (such as disk or network I/O). Event Emitters • Allows you to listen for 'events' and assign functions to run when events occur. • Each emitter can emit different types of events • The 'error' event is special Streams • Streams represent data streams such as I/O.
• Streams can be piped together like in Unix. Modules and Exports • Node.js has a simple module and dependencies loading system • Unix philosophy -> Node philosophy|| - Write programs that do one thing and do it well -> Write modules that do one thing and do it well. • Call the function 'require' with the path of the file or directory containing the module you would like to load, and it returns a variable containing all the exported functions.
Visual Studio Code is a source code editor developed by Microsoft for Windows, Linux and macOS. Visual Studio Code is based on Electron, a framework which is used to deploy Node.js applications for the desktop running on the Blink.
Node Package Manager (NPM) What is NPM? • Official package manager for Node. • Bundled and installed automatically with the environment. How does it work? • Installs the dependencies in the local node_modules folder • In global mode (vs local mode), it makes a node module accessible to all • Can install from a folder, tarball, web. • Can specify dev or optional dependencies • Can also install the dependencies for a project by reading the package.json Introduction to Express What is Express? Express is a minimal, open source and flexible node.js web app framework designed to make developing websites, web apps and APIs much easier.
![Free Free](https://code.visualstudio.com/assets/docs/nodejs/extensions/document_this.gif)
Quickbooks desktop for mac 2017. It's a very popular framework in the Node.js community. Best email service for mac and iphone. Why use Express? • Express helps you respond to requests with route support so that you may write responses to specific URLs • Supports multiple templating engines to simplify generating HTML Little demo. Express and Databases About NoSQL databases The NoSQL databases are an alternative to the relational databases. In a relational database, you have multiple tables who contains data who are different but can be joint with keys, and the model needs to be a detailed (fine-grained) database model.
![Visual Visual](https://code.visualstudio.com/assets/docs/nodejs/nodejs-debugging/dimmed-callstack.png)
In the last couple of years, developers start to prefer more sclalable and flexible data models, a lot easier to manage. With a NoSQL database, no need to develop a detailed database model, you can start quickly, with this advantages and disadvantages. Of course, it's a really short and incomplete summary, you can find a lot of resources about this on the Internet. • Not only SQL • Different types: document based, graph databases, etc. • MongoDB, Couchbase, Azure Cosmos DB, HBase, Cassandra. • Object oriented APIs • Good for large amounts of data, can be scaled.
Debugging and Deploying Node.js Azure Web Apps • Easy to deploy a variety of different websites: node, asp.net, python, etc. • Can install some software from the gallery like WordPress or preconfigured stacks (MEAN stacks). • Has a few limitations such as cannot configure ports, compile native modules for Node. • Can configure custom domains • Can aff FTP users • Can run multiple web sites • Ideal for a production / staging environment Extending Node.js with Azure Web Jobs Azure WebJobs Overview • Ability to run a 'background task' on demand, continuously, or scheduled • Deploy using PAAS - Part of websites • Ideal for tasks such API aggregation, batch processing, image resizing, etc. • Can use Node, Pythno, Bash, etc. Indrocution to creating WebJobs for Node • Looks for a file with 'run'(run.js). If not found looks for any file with supported extension.