Blogger Information
Blog 31
fans 0
comment 0
visits 14271
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
node模块
木子木杉
Original
384 people have browsed it

node 模块

1.核心模块:内置的,开箱即用

  1. http
  2. .createServer(function (request, response) {
  3. response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
  4. response.end("<h2 style='color:red'>今天的天气真好!</h2>");
  5. })
  6. .listen(8081);
  7. console.log("Server running at http://127.0.0.1:8081/");
  1. http
  2. .createServer(function (request, response) {
  3. response.writeHead(200, { "Content-Type": "application/json" });
  4. response.end(`
  5. {
  6. "id":925,
  7. "user":"李同学",
  8. "qq邮箱":"123456789@qq.com"
  9. }
  10. `);
  11. })
  12. .listen(8081);
  13. console.log("Server running at http://127.0.0.1:8081/");
  1. const fs = require("fs");
  2. fs.readFile(__dirname + "/libin.txt", function (err, data) {
  3. if (err) return console.error(err);
  4. console.log(data.toString());
  5. });

2.文件模块:自定义的先声明,在导入

  1. module.exports = {
  2. domain: "WWW.php.cn",
  3. name: "PHP中文网",
  4. getSite() {
  5. return this.name + "(" + this.domain + ")";
  6. },
  7. };

let site = require("./m1.js");
3.第三方模块:npm安装的

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post