文章详情页
node.js - nojs的response.write()如何返回一个html
浏览:169日期:2023-10-02 18:57:04
问题描述
本人学生,正在钻研js。由于听人说前段开发也需要习惯在本地环境中开发web页面就选择了node作为本地环境。已搭建一个简单node服务。
这是代码
var http = require('http');//var path = require('path');http.createServer(function(requrest,response){response.writeHead(200,{'Content-Type': 'text/plain'});//var index = path.extname(’./index.html’);var index = ’<!DOCTYPE html>’+’<html>’+’<head>’+’<meta charset='utf-8'>’+’<title>你好nodejs</title>’+’</head>’+’<body>’+’node.js’+’</body>’+’</html>’;response.write(index);response.end();}).listen(8888);
在我从浏览器访问时直接返回了字符串如图
我还写了一个html文件但是不知道如何让node返回这个index.html给浏览器希望有朋有可以指点以下
问题解答
回答1: 标签:
HTML
上一条:node.js - 使用npm安装vue-cli后,vue还是不可用是什么原因?下一条:html5 - express4 + socket.io 如何在connection的回调外边使用socket.emit方法
相关文章:
1. javascript - 最终生成的jsBundle文件压缩问题2. android - 启动模拟器的,报“Could not automatically detect an ADB binary……”,要怎么解决?3. python - TypeError: tryMsgcode() takes exactly 2 arguments (0 given)4. 关于Java引用传递的一个困惑?5. 如何分别在Windows下用Winform项模板+C#,在MacOSX下用Cocos Application项目模板+Objective-C实现一个制作游戏的空的黑窗口?6. angular.js - angularjs的自定义过滤器如何给文字加颜色?7. 关于docker下的nginx压力测试8. android clickablespan获取选中内容9. docker安装后出现Cannot connect to the Docker daemon.10. javascript - 关于json中获取多个key-value对中多层嵌套key的name
排行榜
