[英]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.