ساخت اینترنت سرور با استعمال از Node
Node.js یک ماژول http ارائه میدهد که میتواند برای ساخت یک خدمت گیرنده HTTP از طراحی اپلیکیشن در مشهد یک سرور استعمال شود.
ساختار تحت دست کم ساختار سرور HTTP میباشد که در پورت 8081 گوش میدهد.
یک فولدر js با اسم server.js ، تولید نمائید.
var http = require(\'http\');
var fs = require(\'fs\');
var url = require(\'url\');
// Create a server
http.createServer( function (request, response) {
// Parse the request containing file name
var pathname = url.parse(request.url).pathname;
// Print the name of the file for which request is made.
console.log("Request for " + pathname + " received.");
// Read the requested file content from file system
fs.readFile(pathname.substr(1), function (err, data) {
if (err) {
console.log(err);
// HTTP Status: 404 : NOT FOUND
// Content Type: text/plain
response.writeHead(404, {\'Content-Type\': \'text/html\'});
} else {
//Page found
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {\'Content-Type\': \'text/html\'});
// Write the content of the file to response body
response.write(data.toString());
}
// Send the response body
response.end();
});
}).listen(8081);
// Console will print the message
console.log(\'Server running at http://127.0.0.1:8081/\');
COPY
اکنون اذن دهید پوشه html تحت را با اسم index.htm در به عبارتی فهرستی که server.js را تولید کردید ساختوساز کنیم.
Hello World!
COPY
درحال حاضر اذن دهید server.js را اعمال کنیم تا فیض را ببینیم :
$ node server.js
COPY
خروجی را پذیرش فرمائید :
Server running at http://127.0.0.1:8081/
ساخت اینترنت سرور با استعمال از Node
Node.js یک ماژول http ارائه میدهد که میتواند برای ساخت یک خدمت گیرنده HTTP از طراحی اپلیکیشن در مشهد یک سرور استعمال شود.
ساختار تحت دست کم ساختار سرور HTTP میباشد که در پورت 8081 گوش میدهد.
یک فولدر js با اسم server.js ، تولید نمائید.
var http = require(\'http\');
var fs = require(\'fs\');
var url = require(\'url\');
// Create a server
http.createServer( function (request, response) {
// Parse the request containing file name
var pathname = url.parse(request.url).pathname;
// Print the name of the file for which request is made.
console.log("Request for " + pathname + " received.");
// Read the requested file content from file system
fs.readFile(pathname.substr(1), function (err, data) {
if (err) {
console.log(err);
// HTTP Status: 404 : NOT FOUND
// Content Type: text/plain
response.writeHead(404, {\'Content-Type\': \'text/html\'});
} else {
//Page found
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {\'Content-Type\': \'text/html\'});
// Write the content of the file to response body
response.write(data.toString());
}
// Send the response body
response.end();
});
}).listen(8081);
// Console will print the message
console.log(\'Server running at http://127.0.0.1:8081/\');
COPY
اکنون اذن دهید پوشه html تحت را با اسم index.htm در به عبارتی فهرستی که server.js را تولید کردید ساختوساز کنیم.
Hello World!
COPY
درحال حاضر اذن دهید server.js را اعمال کنیم تا فیض را ببینیم :
$ node server.js
COPY
خروجی را پذیرش فرمائید :
Server running at http://127.0.0.1:8081/

راهکارهای کاهش CPC در کمپینها