Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. # What is Nodejs
  2. NodeJs is an open source runtime environment. Runtime simply means something that is executable in it's own environment.
  3. Nodejs was built on google's chrome v8 javascript engine.
  4.  
  5. Node is not a convention based platform where everything is thought through such as the database, sessions, authentication, etc.
  6. For example PHP, Ruby on Rails etc. **NodeJs has no idea or does not know which database you are going to hook on to.**
  7.  
  8. Node is not recommmended for high CPU intensive operations like *reading the file system asynchronously, or machine learning or
  9. large arithemetic*. Node is good when it comes to concurrency.
  10.  
  11. In summary, node is not a single bullet for everything.
  12.  
  13. ## What can I create with NodeJs
  14. First of all, javascript can do pretty much anything other languages can do from tooling, building rest api, real time socket etc.
  15.  
  16. - Great for tooling
  17. - Great for creating APIs (REST, Realtime, Sockets) because of it's high concurrency. It can handle a lot of request at the same time.
  18. - Building CDNs
  19.  
  20. In summary, node can do pretty much anything because node is on everything now.
  21.  
  22. ## Installing NodeJs
  23. The advantage of NVM over node is that it is recommended and allows you to run many versions of node whenever.
  24. Moreover, nodejs causes permission errors
  25.  
  26. ## Running Nodejs code
  27. There are two ways of evaluating your javascript code in node
  28.  
  29. **Interactive REPL:** This is mainly for playing around. It stands for READ, EVALUATE, PRINT, LOOP. It is an interactive environment for writing code and it is use for testing things out like the console in the browser. Either than that, it is not used for anything in terms of building full fledge applications.
  30. So the REPL is great for trying things out. Think of the console in the browser. To use REPL just tpe the node command with no args and begin
  31.  
  32. **CLI Executable:** Used for everything else. It is used to execute your node apps but now you pass the path to the file you want to run.
  33.  
  34. ## Globals in Nodejs
  35.  
  36. Node provides you with helpful globals such as:
  37.  
  38. **process:** has information about the environment the program is running in such as the path, OS version, environment variable etc.
  39. **require:** function to find and use modules in the curernt module.
  40.  
  41. **__dirname:** the current directory path.
  42.  
  43. **module:** is the sibling of require where modules are made consumable. Simply put, it is a way of exporting a module so that other modules can require them.
  44.  
  45. **global:** like window, it is the "global object". Almost **never use this**
  46.  
  47. **__filename:** gives you the current filename
  48.  
  49. ## What are modules?
  50.  
  51. Modules are basically encapsulated code. Nodejs uses commonJs for it's module system. Some of the other module systems out there are:
  52.  
  53. -ESM(ecmascript modules)
  54. -AMD(it's outdated)
  55.  
  56. ## Creating Node Modules
  57. Creating modules in node in just regular code that needs to be exported.
  58.  
  59. **
  60.  
  61. ## NPX
  62.  
  63. First of all, npx comes with node. Npx allows you to run locally installed modules on the fly (eg. jest) rather than typing out the exact location of the module let's say >> node modules/jest
  64.  
  65.  
  66.  
  67. Also, incase the module is not installed, npx installs the package before running
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement