javascript - 为什么我不能在本地主机上运行 server.js?
问题描述
所以我有一个带有文件 server.js 的文件夹,在 server.js 里面有这样的代码:
var http = require ('http');
http.createServer(function(req, res){
console.log(req);
console.log("***********************************");
res.writeHead(200, {'Content-Type' : 'text/html'});
res.write('Hello World');
res.end();
}).listen(80);
同样在包含此文件的文件夹中,我安装了节点模块和 npm 以及 package.json 和 package-lock.json 但由于某种原因,当我尝试使用节点 server.json 运行它时,它并没有在端口 80 上运行,而是有时候是这样的。https://imgur.com/KIgHhBm
我怎样才能解决这个问题?我希望能够通过 chrome 打开 server.js,它应该写出 hello world
解决方案
推荐阅读
- sql - OracleAPPS - 无法为供应商获得正确的结果 - 银行查询
- python-2.7 - 如何设置 UDP 套接字的初始序列号 - Python 2.7
- mysql - 使用 phpmyadmin 设置 mysql 服务器连接
- excel - 拆分字符串并在两个字符之间提取
- python - 使用时滞逐组跟踪变化
- r - 带有各种 IF 的向量,加起来和倒计时
- apache-spark - Oozie shell 动作为 spark 作业抛出 NullPointerException
- wordpress - 如何使用 Woo Rest Api 在产品中获取语言
- rest - 发布纯粹是为了使用 HTTP 请求正文
- html - HTML5 - 服务器端事件 - 使用外部文本文件作为数据输入