Skip to content

Instantly share code, notes, and snippets.

@Samangie
Last active July 17, 2018 20:13
Show Gist options
  • Save Samangie/9c85bf0c071a151130ec1b8696625829 to your computer and use it in GitHub Desktop.
Save Samangie/9c85bf0c071a151130ec1b8696625829 to your computer and use it in GitHub Desktop.
Node.js Notes DRAFT

What is Node.js?

Javascript runtime build on Chrome's V8 Javascript engine Javascript running on the server
Used to build powerful, fast & scalable web applications. Uses an event-driven, non-blocking I/O model

You can build a lot with node.js like:

  • REST APIs & Backend Applications
  • Real-Time Services (Chat, Games, etc) -> funktioniert gut mit socket.io,
  • Blogs, CMS, Social Applications
  • Utilities & Tools
  • Anything that is not CPU intensive

Non-blocking I/O

Beispiel Apache Server und PHP jeder Request mach einen neuen Thread, was System Memory braucht. Kann dazu führen, dass das Memory irgendwann voll ist. jeder Prozess muss zuerst beendet werden bevor ein neuer gestartet wird. Node arbeitet mit einem einzelnen Thread und erlaubt uns so mit den Non-blocking I/O unzählige Verbindungen und Request gleichzeitig laufen zu lassen. Diese werden in einem Event Loop gehandelt / verwaltet -> Deswegen heisst es Event Driven System Works on a single thread using non-blocking I/O calls
Supports tens of thousands concurrent connections
Optimizes throughput and saclability in web applications with many I/O operations This makes Node.js apps extremly fast and efficent

Event Loop

Single-threaded Supports concurrency via events and callbacks EventEmitter class is used to bind events and event listeners

Fazit

Beispiel Apache und PHP können nur eine Verbindung/ Request gleichzeitig haben -> synchron Node.js kann unzählige Verbindungen gleichzeitig haben -> asynchron

NPM

Stands for Node.js Package Manager Used to install node programs/ modules Easy to specify and link dependencies

Modules get installed into the node_modules folder, will be created if no one exists. npm install express

Modules get installed into your system (global). can be used not only in our module npm install -g express

Credits

Traversy Media - https://www.youtube.com/watch?v=U8XF6AFGqlc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment