[英]How to Install node.js to broadcast from my home
I am studying Node.js presently and wonder if it is possible to broadcast my sites from one of my home PCs. 我目前正在研究Node.js,想知道是否可以从一台家用PC广播我的站点。
For local publishing I am playing with this code: 对于本地发布,我正在使用以下代码:
const http = require('http');
const fs = require('fs');
const hostname = '127.0.0.1';
const port = 3000;
fs.readFile('index.html', (err, html) => {
if(err){
throw err;
};
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-type','text/html');
res.write(html);
res.end();
});
server.listen(port, hostname, () => {
console.log('Server started on port: '+port);
});
});
But I am not sure what needs to be done to make my sites available to the public. 但是我不确定要使我的网站对公众可用需要做些什么。 How do I set up the "hostname" and whatever else needs to be done to broadcast one or more sites.
如何设置“主机名”以及广播一个或多个站点所需执行的其他任何操作。
I am not asking for a complete robust server code, just a minimal site that says Hello on the WEB. 我不是在要求完整的可靠服务器代码,而只是在Web上说“ Hello”的最小站点。
Many thanks 非常感谢
Easy Route: See Arun's answer. 简易路线:请参阅阿伦的答案。
Formal route: 正式路线:
Informal Route: (Skips to step 3 above) 非正式路线:(跳至上述第3步)
Anyone feel free to correct me/add detail to the steps. 任何人都可以随意纠正我/在步骤中添加细节。
you can host it in platforms like Heroku, firebase etc. they give you a url which is publicly accessible. 您可以将其托管在Heroku,firebase等平台上。它们会为您提供可公开访问的网址。
https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.