nodejs练习笔记(一)

Node.js 安装包:https://nodejs.org/en/download/。Node配置:https://www.runoob.com/nodejs/nodejs-install-setup.html

npm和cnpm安装步骤:https://blog.csdn.net/wjnf012/article/details/80422313

nodejs

一、用 Node 创建 Web 服务器

1.server.js

var http=require('http');
var fs=require('fs');
var url=require('url');

//创建服务器 
http.createServer(function(request,response){
	//解析请求,包括文件名
	var pathname=url.parse(request.url).pathname;
	
	//输出请求的文件名
	console.log("Request for"+pathname+"received");
	
	//从文件系统中读取请求的文件内容
	fs.readFile(pathname.substr(1),function(err,data){
		

猜你喜欢

转载自blog.csdn.net/qq_35831134/article/details/106453830