在linux下搭建好node环境,编写如下node.js文件。
var http = require('http');
http.createServer(function(request,response){
response.writeHead(200,{'Content-Type':'text/plain'});
response.end("hello huangbaokang");
}).listen(8888);
console.log("Server running ....");
运行该文件
[root@localhost node_test]# node node.js
Server running ....
我的ip信息如下:
[root@localhost node_test]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.254.143 netmask 255.255.255.0 broadcast 192.168.254.255
inet6 fe80::f963:84bd:83f7:170f prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:19:88:40 txqueuelen 1000 (Ethernet)
RX packets 15088 bytes 18726001 (17.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3150 bytes 952437 (930.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
浏览器访问8888端口,服务器返回hello huangbaokang