node的内置模块

一、node.js(内置模块/第三方模块/自定义的模块)

  (一)名词:

    1、服务器:一台电脑

    2、接口:地址

    3、前端:能够直接呈现给用户的数据

    4、后端:提供接口给前端

    5、数据库:存储数据

  (二)node http服务(内置模块)

    // 引入内置http模块。

    const http = require("http");

    // 创建http服务 request:请求对象 response:响应对象

    http.createServer(function (request,response) {

    // 响应结束,响应的结果为you love me

    response.end("you love me");

    }).listen(8090,function () {

      console.log("success")

    })

    1、代码修改后,一定一定一定要重启

    2、end():只能使用一次,其响应的值只能为字符串。

    3、响应结束后,服务代码依然会执行。结束的是响应。

    4、可以通过记事本,另存为改变文件的编码格式。

    5、服务不允许同时启动多次。 listen EADDRINUSE :::80

    6、*****:node 是没有文件夹容器概念的。

// 引入内置模块HTTP
const http = require("http");
// 创建HTTP服务
const server = http.createServer((req,res)=>{ //req请求对象,res响应对象
    // 响应结束及结果,只能结束一次,并且响应值只能为字符串类型
    res.end("lfy");
});
// 监听HTTP服务
server.listen(9000,()=>{
    console.log("success");
});
原文地址:https://www.cnblogs.com/liufuyuan/p/10625975.html