入门

http://nodejs.cn/

1
2
3
4
➜  ~ node -v
v12.4.0
➜  ~ npm -v
6.11.2

Node.js 控制台

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
➜  ~ node
Welcome to Node.js v12.4.0.
Type ".help" for more information.
>
> console.log("Hello World.");
Hello World.
undefined

> .help
.break    Sometimes you get stuck, this gets you out
.clear    Alias for .break
.editor   Enter editor mode
.exit     Exit the repl
.help     Print this help message
.load     Load JS from a file into the REPL session
.save     Save all evaluated commands in this REPL session to a file

> .exit
➜  ~
1
2
3
4
5
// hello.js
console.log("Hello World!");

var mystr = "Hello Node.js!";
console.log(mystr);
1
2
3
➜  ~ node hello.js 
Hello World!
Hello Node.js!