简体   繁体   English

node.js 可以让 Web 浏览器(客户端)访问我计算机中的任何目录吗?

[英]Can node.js let a Web browser (client) get access to any directory in my computer?

Just to let you know I'm very new to setting up a Web server and I'm questioning to organize my input.只是为了让您知道我对设置 Web 服务器非常陌生,我正在质疑如何组织我的输入。 I set up http-server implementing Node.js script below:我在下面设置了实现 Node.js 脚本的 http-server:

const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World and Youaaaa.');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

  • I guess this code set up a http-server on my computer and let the port 3000 of the http-server open to the Internet.我猜这段代码在我的计算机上设置了一个 http-server,并让 http-server 的端口 3000 向 Internet 开放。 Does that mean the Internet can get access to any directory in my computer from C drive to Desktop?这是否意味着 Internet 可以访问我计算机中从 C 驱动器到桌面的任何目录?

  • Which directory in my computer does this url http://127.0.0.1:3000/ indicate?这个 url http://127.0.0.1:3000/表示我电脑中的哪个目录? If I add to this some words like C:/UserName/Desktop/sample.js and set it on Web Browser's URL form, can the Web browser implement sample.js file? If I add to this some words like C:/UserName/Desktop/sample.js and set it on Web Browser's URL form, can the Web browser implement sample.js file?

I guess this code set up a http-server on my computer and let the port 3000 of the http-server open to the Internet.我猜这段代码在我的计算机上设置了一个 http-server,并让 http-server 的端口 3000 向 Internet 开放。 Does that mean the Internet can get access to any directory in my computer from C drive to Desktop?这是否意味着 Internet 可以访问我计算机中从 C 驱动器到桌面的任何目录?

No.不。

You haven't written any code which lets your Node.js program read a file.您还没有编写任何代码让您的 Node.js 程序读取文件。 Let alone a file determined by user input.更不用说由用户输入确定的文件了。

Which directory in my computer does this url http://127.0.0.1:3000/ indicate?这个 url http://127.0.0.1:3000/表示我电脑中的哪个目录?

No directory.没有目录。

Look at your code:看看你的代码:

 res.end('Hello World and Youaaaa.');

That's a hard coded string, not a reference to any file.这是一个硬编码字符串,而不是对任何文件的引用。

If I add to this some words like C:/UserName/Desktop/sample.js and set it on Web Browser's URL form, can the Web browser implement sample.js file? If I add to this some words like C:/UserName/Desktop/sample.js and set it on Web Browser's URL form, can the Web browser implement sample.js file?

No.不。

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

相关问题 Node.js azure web 应用程序无法访问我的路由 - Node.js azure web app can't access my routes 如何将node.js Web应用程序上传到openshift? 它不是在git上,而是在我的计算机上? - How do I upload my node.js web app to openshift? It is NOT on git, but just on my computer? 在我的 node.js 项目中无法获得客户 ip 的正确信息 - Can't get the correct of a client ip in my node.js project 如何在浏览器上运行 node.js 客户端 - how to run node.js client on browser 如何在节点js中获取客户端计算机名称 - How to get client computer name in node js 如何在没有 SSH 的情况下从我的计算机本地远程访问 MySQL 数据库(通过 Node.js 应用程序)? - How to remote access MySQL database locally from my computer(through Node.js app) without SSH? Node.js Web应用程序浏览器兼容性 - Node.js web application browser compatibility 具有 JavaScript 执行功能的 Node.js Web 浏览器 - Node.js web browser with JavaScript execution 在web浏览器或node.js中异步/等待? - Async/await in web browser or in node.js? 如何使用 socket.io 在客户端(网络浏览器)中显示来自 node.js 服务器的实时数据? - How to use socket.io to display realtime data in the client (web browser) from the node.js server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM