命令行工具
- 切换盘符 直接
d:
ctrl + c
退出clear
||cls
清除全屏
node代码操作
node创建服务器
let http = require('http')
http.createServer(function(req, res) {
res.writeHead(200, {
'Content-Type': 'text/html'})
res.end('success')
}).listen(3000)
console.log('The server is running!')
模块系统
一个文件就是一个模块
暴露接口: exports
|| module.exports
exports
是module.exports
的引用
//暴露变量
let a = 'string'
exports.a = a
//暴露方法
function sayHi() {
console.log('Hi!b!')
}
exports.sayHi = sayHi
//暴露多个数据
module.exports = {
a: a,
sayHi: sayHi
}
只能使用module.exports
暴露多个值,不能使用exports
,exports
只是module.exports
的一个引用,重设为对象会改变引用
引入: require()
默认模块不需要路径
let http = require('http')
自定义js文件需要路径
let input = require('./a.js')
//引入变量
let input = require('./a.js')
console.log(input.a)
//使用方法
input.sayHi()
node框架-express
使用 npm 配置express
下载 express
npm install express-generator -g
建立项目
express -e project-name
进入项目目录
cd project-name
安装所有依赖
npm install
运行(每次更改代码之后需要重启生效)
npm run start
静态资源
-
地址栏中不用输入
public
-
地址栏默认以
public
为根目录,直接以原始文档路径进行访问
路由
form表单的提交
<!--
login.html
-->
<form action="/users/log