搭建node服务器
一. 下载node
1. 下载 node js
2. 写 js 代码
3. 用 node 去 运行 js
二. node 搭建服务器
5.桌面新建文件 aaa
6. 终端 (win + r cmd 回车)
7. 终端 输入: cd aaa
8. 确定 终端是否 处于 aaa 路径之下
9. 终端 输入 npm init
10. 一直 回车
11. 检查 aaa 文件夹
12. 将 aaa 文件夹 拖入 vsCode中
13. 在 vs code 中查看 package.json 文件
发现 里面有一行代码 index.js
14. 通过 vsCode 在 aaa 文件夹中创建 index.js 文件
15. 在 index.js 文件中 写 服务器代码
百度 ---> koa2 ---> 滚动 ---> HelloWorld ---> 赋值粘贴]
16. 运行 该 index.js 文件
node index.js
Error: Cannot find module 'koa'
解决办法: cnpm install koa --save
( 你的电脑没有cnpm
需要在你的电脑上的终端中 安装 cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
)
17. 再一次 执行 node index.js
光标闪在 最左侧, 证明 程序 运行起来了
18. 终端 ctr + c 停止项目
19. 在 index.js 中增加一行代码
7: console.log("服务器, 跑在3000端口上....")
20. 重新运行项目 node index.js
21. 浏览器 输入 localhost:3000 回车
22. 每次 当 index.js 中的代码修改之后, 需要
先停止 项目 ctr + C
再运行 项目 node index.js
再刷新浏览器 界面 localhost:3000