Advertisement
Advertisement

More Related Content

Advertisement

Overview of Node JS

  1. JACOB NELSON SOFTWARE ARCHITECT
  2. Node.js is not a silver-bullet new platform that will dominate the web development world. Instead, it’s a platform that fills a particular need.
  3. A word of warning There are some really excellent JavaScript people out there. I'm not one of them.
  4. Node JS is a powerful tool for controlling web servers, building applications, and creating event- driven programming and it brings JavaScript, a language familiar to all web developers, into an environment independent of web browsers.
  5. Node.js® is a JavaScript runtime built on Chrome'sV8 JavaScript engine.
  6. Runtime is when a program is running (or being executable).That is, when you start a program running in a computer, it is runtime for that program.
  7. Node.js is not a JavaScript framework
  8. Node.js allows you to run JavaScript code in the backend, outside a browser.
  9. +
  10. Node.js ships with a lot of useful modules, so you don't have to write everything from scratch
  11. Thus, Node.js is really two things: a runtime environment and a library.
  12. Requirements ▪ JavaScript ▪ Command-LineTool
  13. V8 TheV8 JavaScript Engine is an open source JavaScript engine developed byThe Chromium Project for the Google Chrome web browser. It has seen used in many other projects, such as Couchbase, MongoDB and Node.js. https://en.wikipedia.org/wiki/V8_(JavaScript_engine)
  14. Threading Node is single-threaded and uses a concurrency model based on an event loop. It is non-blocking, so it doesn't make the program wait, but instead it registers a callback and lets the program continue. This means it can handle concurrent operations without multiple threads of execution, so it can scale pretty well.
  15. Installing Node If you're using OS X orWindows, the best way to install Node.js is to use one of the installers from the Node.js download page. If you're using Linux, you can use the installer, or you can check Node Source's binary distributions to see whether or not there's a more recent version that works with your system.
  16. Test node -v
  17. npm, the official Node package manager npm is the package manager for JavaScript. npm makes it easy for JavaScript developers to share and reuse code, and it makes it easy to update the code that you're sharing.
  18. npm, the official Node package manager Node comes with npm installed so you should have a version of npm. However, npm gets updated more frequently than Node does, so you'll want to make sure it's the latest version.
  19. npm, the official Node package manager ▪ It installs application dependencies locally, not globally. ▪ It handles multiple versions of the same module at the same time. ▪ You can specify tarballs or git repositories as dependencies. ▪ It's really easy to publish your own module to the npm registry. ▪ It's useful for creating CLI utilities that others can install (with npm) and use right away.
  20. Npm behind firewall npm config set proxy http://gateway.zscaler.net:9400 npm config set https-proxy http://gateway.zscaler.net:9400
  21. Updating npm npm install npm@latest -g
  22. Test npm -v
  23. Your First Program console.log('HelloWorld');
  24. npm init The npm init command is a step-by-step tool to scaffold out your project. It will prompt you for input for a few aspects of the project in the following order:
  25. npm init ▪ The project's name ▪ The project's initial version ▪ The project's description ▪ The project's entry point (meaning the project's main file) ▪ The project's test command (to trigger testing with something like Standard) ▪ The project's git repository (where the project source can be found) ▪ The project's keywords (basically, tags related to the project) ▪ The project's license (this defaults to ISC - most open-source Node.js projects are MIT)
  26. npm init Once you run through the npm init steps above, a package.json file will be generated and placed in the current directory. If you run it in a directory that's not exclusively for your project, don't worry! Generating a package.json doesn't really do anything, other than create a package.json file.You can either move the package.json file to a directory that's dedicated to your project, or you can create an entirely new one in such a directory.
  27. npm init Once you run through the npm init steps above, a package.json file will be generated and placed in the current directory. If you run it in a directory that's not exclusively for your project, don't worry! Generating a package.json doesn't really do anything, other than create a package.json file.You can either move the package.json file to a directory that's dedicated to your project, or you can create an entirely new one in such a directory.
  28. npm init options If you invoke it with -f, --force, -y, or --yes, it will use only defaults and not prompt you for any options.
  29. package.json package.json file can be described as a manifest of your project that includes the packages and applications it depends on, information about its unique source control, and specific metadata like the project's name, description, and author.
  30. package.json
  31. package.json package.json also contains a collection of any given project's dependencies.These dependencies are the modules that the project relies on to function properly.
  32. package.json - dependencies Dependencies are specified in a simple object that maps a package name to a version range.The version range is a string which has one or more space-separated descriptors. Having dependencies in your project's package.json allows the project to install the versions of the modules it depends on. By running an install command inside of a project, you can install all of the dependencies that are listed in the project's package.json - meaning they don't have to be (and almost never should be) bundled with the project itself.
  33. package.json - devDependencies It also allows the separation of dependencies that are needed for production and dependencies that are needed for development. In production, you're likely not going to need a tool to watch yourCSS files for changes and refresh the app when they change.
  34. package.json – module version ▪ version Must match version exactly ▪ >version Must be greater than version ▪ >=version etc ▪ <version ▪ <=version~version "Approximately equivalent to version" ▪ ^version "Compatible with version" ▪ 1.2.x 1.2.0, 1.2.1, etc., but not 1.3.0
  35. package.json – module version ▪ http://... ▪ * Matches any version ▪ "" (just an empty string) Same as * ▪ version1 - version2 Same as >=version1 <=version2. ▪ range1 || range2 Passes if either range1 or range2 are satisfied. ▪ git... ▪ user/repo See 'GitHub URLs' below ▪ tagA specific version tagged and published as tag ▪ path/path/path
  36. Modules - Installation npm install <-g> module name
  37. Modules – Installation npm install Once you run this, npm will begin the installation process of all of the current project's dependencies.
  38. Modules – Installation Options npm install <module> --save when installing a module: --save, it will install and save it as an entry in the dependencies npm install <module> --save-dev when installing a module: --save-dev, it will install and save it as an entry in the devDependencies
  39. Modules – Listing Sometimes is useful to see the list of packages that you have installed on your system.You can do that with the following commands: # list all installed modules with dependencies npm ls # list all installed modules without dependencies npm ls --depth=0 # list all installed globally dependencies npm ls -g --depth=0
  40. Extraneous Modules Modules which are installed and are found on node_modules folder, but not included as Dependency or devDependency in package.json
  41. Module – uninstallation # uninstall package and leave it listed as dep npm uninstall <package_name> # uninstall and remove from dependencies npm uninstall --save <package_name> # uninstall global package npm uninstall -g <package_name> # remove uninstalled packages from node_modules npm prune
  42. Modules – view all versions of an NPM Package The easy way to view all released versions of an npm package is to use the following command npm show <module>@* version
  43. Modules - Importing ▪ Java or Python use the import function to load other libraries, ▪ PHP and Ruby use require. ▪ In Node you can load other dependencies using the require keyword.
  44. Modules - Importing ▪ For example, we can require some core modules: ▪ var http = require('http'); ▪ var dns = require('dns');
  45. Modules - Importing What node.js will do in this case, is to first look if there is a core module named http, and since that's the case, return that directly. But what about non-core modules, such as 'mysql'? In this case node.js will walk up the directory tree, moving through each parent directory in turn, checking in each to see if there is a folder called 'node_modules'. If such a folder is found, node.js will look into this folder for a file called 'mysql.js'. If no matching file is found and the directory root '/' is reached, node.js will give up and throw an exception.
  46. Modules - Importing ▪ We can also require relative files: ▪ var myFile = require('./myFile'); // loads myFile.js
  47. callbacks In asynchronous programming we do not return values when our functions are done, but instead we use the continuation-passing style (CPS). With this style, an asynchronous function invokes a callback (a function usually passed as the last argument) to continue the program once the it has finished.
  48. When Not to Use? ▪ CPU heavy apps ▪ Simple CRUD / HTML apps ▪ NoSQL + Node.js
  49. When to Use? ▪ JSON APIs ▪ Single page apps ▪ Streaming Data ▪ Soft Real time Applications
  50. ▪ https://www.guru99.com/node-js-tutorial.html ▪ http://www.tutorialsteacher.com/nodejs/nodejs-basics ▪ https://www.javatpoint.com/what-is-nodejs ▪ http://adrianmejia.com/blog/2016/08/19/Node-Package-Manager-NPM- Tutorial/ ▪ https://nodesource.com/blog/an-absolute-beginners-guide-to-using-npm/ ▪ Best Practices ▪ https://www.codementor.io/mattgoldspink/nodejs-best-practices- du1086jja
Advertisement