Just to let you know I'm very new to setting up a Web server and I'm questioning to organize my input. I set up http-server implementing Node.js script below:
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. Does that mean the Internet can get access to any directory in my computer from C drive to Desktop?
Which directory in my computer does this url http://127.0.0.1:3000/
indicate? 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. Does that mean the Internet can get access to any directory in my computer from C drive to Desktop?
No.
You haven't written any code which lets your Node.js program read a file. Let alone a file determined by user input.
Which directory in my computer does this url http://127.0.0.1:3000/ indicate?
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?
No.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.