Guest User

Untitled

a guest
Feb 25th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. Node is an open-source, cross-platform runtime system for developing applications in JavaScript. In other words, it runs JavaScript outside the browser.
  2.  
  3. Install Node
  4. To get started, run the following command.
  5.  
  6. brew install node
  7. Once it finishes, run the following command.
  8.  
  9. node -v
  10. And you'll see something like this.
  11.  
  12.  
  13.  
  14. Discover the Node Shell
  15. The interactive Node shell provides a read-evaluate-print loop (REPL) for JavaScript programs.
  16.  
  17. To get started, launch the Node shell by running the following command.
  18.  
  19. node
  20. And you'll see something like this.
  21.  
  22.  
  23.  
  24. After the prompt >, you can type a line of JavaScript code and then press the Enter key to run it. For example, type and run the following JavaScript program.
  25.  
  26. 1 + 2
  27. And you'll see something like this.
  28.  
  29.  
  30.  
  31. The Node shell is a great tool for learning and experimenting with JavaScript.
  32.  
  33. Play around with JavaScript on your own. When you're done, type .exit and press the Enter key to quit the Node shell.
  34.  
  35. TIP: You can also press the Command + D keys to exit the Node shell.
  36.  
  37. Discover the Node Interpreter
  38. Given a JavaScript program stored in a file, the Node interpreter reads it, evaluates it, and then quits.
  39.  
  40. Unlike the Node shell, the Node interpreter is not interactive. In other words, the Node interpreter won't automatically print the result of each line or loop waiting for you to give it more input. It just reads and evaluates a JavaScript program file.
  41.  
  42. Despite these deficiencies, you'll use the Node interpreter more frequently. Let's try it out.
  43.  
  44. First, open a new JavaScript program file in Atom.
  45.  
  46. atom ~/Desktop/test.js
  47. TIP: JavaScript program files end with a .js extension.
  48.  
  49. Then type the following program into the file.
  50.  
  51. 1 + 2;
  52. Save the file and run the program using the Node interpreter.
  53.  
  54. node ~/Desktop/test.js
  55. Weird, nothing happened. Remember, the Node interpreter won't print anything unless told. Jerk! 😤
  56.  
  57. Change the program so it reads like this.
  58.  
  59. console.log(1 + 2);
  60. Save the file and re-run the program.
  61.  
  62. node ~/Desktop/test.js
  63. And you'll something like this.
  64.  
  65.  
  66.  
  67. Play around with JavaScript on your own. When you're done, remove the test.js file by running the following command.
  68.  
  69. rm ~/Desktop/test.js
Add Comment
Please, Sign In to add comment