Blogger Information
Blog 33
fans 0
comment 0
visits 17019
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
fetch api,npm 与 node 模块的使用
lucaslwk
Original
448 people have browsed it

fetch api,npm 与 node 模块的使用

一.fetch_api,async,await

fetch

  1. let url = "https://jsonplaceholder.typicode.com/todos/1";
  2. //fetch api
  3. fetch(url)
  4. .then((response) => response.json())
  5. .then((json) => console.log(json))
  6. .catch((err) => console.log("error"));
  7. //ecma2017,async await 简化fetch
  8. async function getUser(url) {
  9. try {
  10. const response = await fetch(url);
  11. const result = await response.json();
  12. console.log(result);
  13. } catch (error) {
  14. console.log("error");
  15. }
  16. }
  17. getUser(url);

二.npm 安装与删除包的常用操作

  1. npm i axios :全部安装
  2. npm i axios -S:安装生产依赖
  3. npm i axios -D:安装开发依赖
  4. npm ui axios:删除包

三.node 模块

  1. //核心模块
  2. const http = require("http");
  3. console.log(http.Agent);
  4. //文件模块
  5. const site = require("./outside.js");
  6. console.log(site.getSite());
  7. //第三方模块: npm安装的
  1. let site = "php中文网";
  2. let getSite = function () {
  3. return site + " (php.cn)";
  4. };
  5. exports.site = site;
  6. exports.getSite = getSite;
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