兄弟会精英班 - 学习笔记(五)

2016-09-12  本文已影响0人  bastonly

Nodejs的基本语法

Nodejs Js的编译运行环境,运行在服务器端的 JavaScript,事件驱动I/O服务端JS运行环境,
基于Google的V8引擎,执行JS的速度非常快,性能非常好。

Js基础知识学习参考 W3cSchool

服务器端执行 node test.js , 屏幕上打印出 Hello World!,

if ( ) { }
else if ( ) { }
else { }

for (var i; i < 10; i++) { }

switch ( n )
{
case 1:
执行代码 1
break;
case 2:
....
default:
}

创建http服务器

const http = require("http"); //引入http模块
const ip = ""; //设置服务器IP地址
const port = ; //设置服务器端口

var a =function(req, res) {
res.writeHead(200, {'content':'text/html'} ); //发送http头部,http状态值200,内容类型text/html
res.end("Hello World \n"); //发送相应数据Hello World
}

var server = http.createServer( a );

var c = function(){
console.log("Server is running at http://", http);
}

server.listen( port, ip, c);

上一篇 下一篇

猜你喜欢

热点阅读