• nodejs的基础(1)


    node:单线程可以通过回调进行异步操作。

    node核心

          非阻塞

          单线程

          事件驱动

          事件:EventEmitter

    node模块的分类

        1:核心模块

        2:文件模块

        3:第三方模块

    创建模块的流程

        1:创建模块 teacher.js

        2:导出模块 exports.add=function(){}

        3:加载模块  var teacher=require("../teacher.js")

        4:使用模块   teacher.add('scoot');

    node可以调用的方法

       1:url.parse(urlStr[,pareQueryString][,slashesDenoteHost]);  //后2个参数默认为false,第二个为true时会把query变成一个对象,原来是字符串,第三个参数为true时会把没有协议的地址正常解析

       eg:

            url.parse('http://www.imooc.com/video');

       把url地址解析为一个对象。

         {

          href: 完整地址

          protocol: 协议

          slashes: 协议后是否使用双斜杠

          auth :基本的认证

          hostname:主机名 

          port: 端口 

          host: 主机

          pathname: 路径名('/video')

          path:路径名('/video')

         search: 查询字符串带?

         query : 查询字符串,不带?

         hash :带#的锚点

      }

    2:url.format(urlObj)  //传入一个对象,把一个合法url的对象生成一个url地址

    3:url.reolve(from,to)  域名+地址生成一个合法的url

    eg: url.reolve('http://www.imooc.com/','/video/6710');

    结果为:http://www.imooc.com/video/6710

    4:querystring//把请求参数解析成对象

    querystring.stringify({name:'scoot',course:['jaxj','node'],from:''})

    结果为

    name=scoot&course=jaxj&course=node&from='

    querystring.stringify({name:'scoot',course:['jaxj','node'],from:''},',')

    结果

    name=scoot,course=jaxj,course=node,from='querystring.stringify({name:'scoot',course:['jaxj','node'],from:''},',',':')

    结果

    name:scoot,course:jaxj,course:node,from:'

    5:转义  querystring.escape('<哈哈>');

    结果

    '%3C%E5%93%88%E5%93%88%3E'

    6:反转义

    querystring.unescape('%3C%E5%93%88%E5%93%88%3E');

    结果:

       哈哈

  • 相关阅读:
    CNN comprehension
    Gradient Descent
    Various Optimization Algorithms For Training Neural Network
    gerrit workflow
    jenkins job配置脚本化
    Jenkins pipeline jobs隐式传参
    make words counter for image with the help of paddlehub model
    make words counter for image with the help of paddlehub model
    git push and gerrit code review
    image similarity
  • 原文地址:https://www.cnblogs.com/sliuie/p/5176941.html
Copyright © 2020-2023  润新知