简体   繁体   English

树莓派 3 上的 Node.js 服务器未在 web 浏览器中加载

[英]Node.js server on raspberry pi 3 not loading in web browser

I am new to node.js on the raspberry pi and am trying to get my first local server up and running.我是树莓派上 node.js 的新手,我正在尝试启动并运行我的第一台本地服务器。 I have my computer remote ssh into my pi and am using vscode to run my node.js file.我将计算机远程 ssh 安装到我的 pi 中,并使用 vscode 运行我的 node.js 文件。

 console.log('test') var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/html' }); res.end('Hello World;'). });listen(8080);

When running the basic local server file, I am unable to access the page at localhost:8080.运行基本的本地服务器文件时,我无法访问 localhost:8080 的页面。 The terminal correctly displays my logged message, however, so it is running.但是,终端正确显示了我记录的消息,因此它正在运行。 This may have something to do with me possibly incorrectly installing node (I'm not sure if i did or need to download the Linux Binaries ARM) on my pi.这可能与我可能在我的 pi 上错误地安装节点有关(我不确定我是否需要或需要下载 Linux Binaries ARM)。

Your raspberry pi & node server configuration seems to be fine.您的树莓派和节点服务器配置似乎很好。

If you are trying to check from the terminal you must use curl如果您尝试从终端检查,则必须使用curl

in your case it will curl http://localhost:8080 and you will receive the server response.在您的情况下,它将curl http://localhost:8080并且您将收到服务器响应。

If you want to check for your remote machine browser you would need to connect either using raspberry pi IP or the hostname.如果要检查远程计算机浏览器,则需要使用树莓派 IP 或主机名进行连接。 You can try below commands over ssh to get IP or hostname您可以通过 ssh 尝试以下命令来获取 IP 或主机名

hostname        // for hostname

hostname -i     // for local IP

hostname -I     // for public IP```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM