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
  • 相关阅读:
    pyftpdlib 搭建FTP服务器
    numpy 解一道简单数学题
    python 实现词云
    个人的毕业长足---- 暴走北京
    Tensorflow of GPU, hello fish by version 0.8.
    图像识别
    用一个Inception v3 架构模型实现简单的迁移学习(译:../tensorflow/tensorflow/examples/image_retraining/retrain.py)
    19.液晶屏的原理
    18.DMA-6410
    17.DMA-2440
  • 原文地址:https://www.cnblogs.com/amiezhang/p/8041809.html
Copyright © 2011-2022 走看看