zoukankan      html  css  js  c++  java
  • node.js浅谈

    相信大家对node.js也很不陌生吧,现在我来总结一下常用的吧~

    我们Web全栈工程师最多的就是用Node作为后台了,Node.js虽然可以作为后台语言,但是相对于Java那些老牌后台语言真是一点优势都没有,Node.js更多是作为工具为我们的开发提供便利而已。

    Node.js = 后台(35%) + 工具(65%)


    后台基本用法:

    const http = require('http');
    const fs = require('fs');
    
    const server = http.createServer((req,res)=>{
      fs.readFile(req.url.replace(/^//,''),(err,data)=>{
        if(err){
          res.writeHeader(404);
          res.write('not found!!');
        }else{
          res.write(data)
        }
        res.end();
      })
    });
    server.listen(8088);

    上面实现了简单的文件读取的服务器最基本功能,要实现更多功能就要引入其他库,写其他的逻辑


    工具包括——Webpack、Gulp、Grunk等,管理这些工具我们就用到npm(Node Package Manager),安装Node时就被捆绑安装了这个工具包管理工具

    npm常用指令:

    //安装 install或者i
    npm i jquery@2.x -g --save-dev
    
    //卸载 uninstall
    npm uninstall jquery@2.x -g --save
    
    //创建 package.json
    npm init

    --save 更新package.json中dependencies下的对应信息

    --save-dev 更新package.json中devDependencies下的对应信息

    -g 全局环境下的操作

    在国内,我们推荐使用cnpm,用法和npm一模一样,先安装,然后所有指令将npm改成cnpm就可以了

    npm install -g cnpm --registry=https://registry.npm.taobao.org
  • 相关阅读:
    K-means Algorithm
    Naive Bayes Algorithm
    Generalized Linear Models
    Support Vector Machine
    wordpress迁移
    Gaussian Discriminant Analysis
    Locally Weighted Regression
    Matlab绘图高级部分
    Supervised Learning-Regression
    html 字符串互转DOM
  • 原文地址:https://www.cnblogs.com/amiezhang/p/8041809.html
Copyright © 2011-2022 走看看