zoukankan      html  css  js  c++  java
  • Node.js 的初体验

    例子1:

    1.首先第一步 :要 下载 node.js。 官网 上可以下载 

       下载完后,是这个玩意。

    2. 打开 node.js ,然后输入

    // 引入http模块
    var http = require("http"); 
    
    // 创建server,指定处理客户端请求的函数
    http.createServer(
        function(request, response) { 
            response.writeHead(200, {"Content-Type": "text/plain"}); 
            response.write("Hello World!"); 
            response.end(); 
        }
    ).listen(8000); 
    
    console.log("Hello World is listening at port 8000");

    显示结果为

    3. 在浏览器 显示 :输入 localhost:8000,显示

    例子2:

    1. 打开node.js ,输入

    var sys = require("util")
    var http = require("http");
    http.createServer(function(request, response) {
     //   response.sendHeader(200, {"Content-Type": "text/html"});
        response.writeHeader(200, {"Content-Type": "text/html"});
        response.write("Hello World!");
     //   response.close();
        response.end();
    }).listen(8080);
    sys.puts("Server running at http://localhost:8080/");
     
     
    2.打开游览器 输入 : http://localhost:8080/
    显示图为:

    例子3

      1.打开 node.js 

         输入var http = require('http');

     
    http.createServer(function (request, response) {
      response.writeHead(200, {'Content-Type': 'text/plain'});
      response.end('Hello World\n');
    }).listen(8124);
     
    console.log('Server running at http://127.0.0.1:8124/');

      2.打开浏览器 ,输入http://localhost:8124/:

      显示界面为




  • 相关阅读:
    django LDAP
    Python egg
    皮皮书屋
    Linux运维
    bash shell 快捷键汇总
    linux ldconfig
    Linux set env export declare unset
    OpenStack
    【LeetCode】258. Add Digits
    一个"Median Maintenance"问题
  • 原文地址:https://www.cnblogs.com/bingyizhihun/p/8422049.html
Copyright © 2011-2022 走看看