安装命令
yarn global add node-dev
//或者
npm install -g node-dev
运行
Usage
Just run node-dev as you would normally run node:
node-dev server.js
2.(用JS)在用JS来添加css文件
//在HTML加
<link rel="stylesheet" href="style.css">
//在服务器路由上加
else if (path==='/style.css'){
response.statusCode = 200
response.setHeader('Content-Type', 'text/css;charset=utf-8')
const string3=fs.readFileSync('public/style.css')
response.write(string3)
response.end()
}
调用对象的open方法
const request=new XMLHttpRequest()
监听对象的onload和onerror事件
request.open('get','/style.css')
调用对象的send方法
request.onload=()=>{
console.log('请求成功了')
const style=ducoment.createElement(style)
style.innerHtml(request.response)
document.head.appendChild(style)
}
request.send()
request.onreadystatechange=()=>{
//
if(request.readyState>200 && request.readyState<300){
//创建一个div标签
const div=document.createElement('div')
//将获取来的内容写入div标签
div.innerHTML=request.response
//将标签插入HTML中
document.body.appendChild(div)
}else{
alert('请求2.html失败')
}
}