# node.js 学习开始
版本
node -v
V 12.16.1
- 在cmd 命令行输入 node 即进入node的交互环境。
node
在node环境中可以输入js代码并立马执行
node
Welcome to Node.js v12.16.1.
Type ".help" for more information.
100+200
300
1
2
3
4
5
2
3
4
5
# npm
- npm 是NODE.js 的包管理工具(package manager)
- 大家可以将自己开发的模块打包上传到npm,需要时可以直接下载,开源共享。
- 重要的是,如果我们要使用模块A,而模块A又依赖于模块B,模块B又依赖于模块X和模块Y,npm可以根据依赖关系,把所有依赖的包都下载下来并管理起来。否则,靠我们自己手动管理,肯定既麻烦又容易出错
# 第一个node程序(hello Word)
- 新建一个js文件,命名hello.js,输入以下代码
console.log('hello word')
1
- 使用cmd命令cd 进入到当前js文件的目录,然后 输入 node hello.js,
C:\Users\Administrator>cd desktop
C:\Users\Administrator\Desktop>node hello.js
hello word
1
2
3
2
3
hello word 成功输入,说明程序运行成功!
# 注意
一定要先进入当前js文件的目录,不然会报错