美文网首页技术瓶
nodejs 开发环境搭建以及sublime插件推荐

nodejs 开发环境搭建以及sublime插件推荐

作者: udzhou | 来源:发表于2018-05-09 16:22 被阅读0次
  1. 使用 nvm 安装 nodejs ,以及版本管理,不推荐安装包安装
  2. npm 设置
    // 由于官方 npm 地址访问过慢,故推荐淘宝源
    npm --registry https://registry.npm.taobao.org install express // 临时使用
    npm config set registry https://registry.npm.taobao.org // 持久使用
    // 配置后可通过下面方式来验证是否成功 
    npm config get registry
    
    // npm查看全局安装过的包
    npm list -g --depth 0
    // 显示 npm 全局模块的安装路径
    npm list -g | head -n1
    
  3. 安装进程管理工具pm2
    npm install -g pm2
    pm2 start index.js --name test // 启动某个项目
    pm2 logs // 查看日志
    pm2 start ecosystem.json // 配置文件启动
    {
      /**
       * Application configuration section
       * http://pm2.keymetrics.io/docs/usage/application-declaration/
       */
      "apps": [{
      "name": "xx_game-1",
      "script": "index.js",
      "cwd": "./game",
      "watch": false,
      "ignore_watch": ["node_modules", ".git", ".svn"],
      "env": {
        "PORT": 7701,
        "ISMASTER": 1,
        "SERVID": 1
      },
      "env_development": {},
      "exec_mode": "fork",
      "merge_logs": true,
      "autorestart": false,
      "max_restarts": 1
      }]
    }
    
    
    
  4. sublime text3 插件安装
    • 先安装插件管理工具 Package Control安装教程
    • 安装格式化代码插件 html/css/js prettify , 轻松统一格式代码
    • 安装插件 SublimeLinter 检查代码错误,并安装 SublimeLinter-jshint 检查js代码,同时需要 npm install -g jshint , 点击 SublimeLinter 用户配置如下:
      {
          "linters": {
              "jshint": {
                  "@disable": false,
                  "args": [
                      "--config",
                      "D:\\config\\jshintrc" // 你的jshintrc配置路径
                  ],
                  "excludes": []
              },
          },
      }
      
      // jshintrc 文件例子
      {
          // 提示项定制
          "eqeqeq": false,    // 不提示使用 == 和 !== 的一般比较
          "-W041": false,     // 不提示使用 == 和 !== 与''或0的比较
          "eqnull": true,     // 不提示和 null 比较
          "sub": true,        // 不提示使用 [] 形式访问对象属性
          "node": true, // 感知nodejs
          "shadow": true,
          "loopfunc": true,
          "-W065": true,
          "-W032": true,
          "esversion": 6, // es版本
          "bitwise": true,    // 提示位操作符的使用(防止逻辑运算符笔误)
          "curly": true,      // 提示条件语句和循环语句的语句体没有使用大括号包裹
          "immed": true,      // 提示立即执行函数没有使用小括号包裹
          "latedef": "nofunc",// 提示变量使用先于变量声明(但函数声明除外)
          "noarg": true,      // 提示 arguments.caller 和 arguments.callee 的使用
          "undef": true,      // 提示变量未声明就使用(跨文件全局变量请在predef中显式列出)
          "unused": true,     // 提示未使用的变量
          // 环境感知
          "browser": true,    // 感知浏览器API,对应变量默认为已声明的,如 document, navigator, FileReader
          "jquery": true,     // 感知jQuery API
          "lastsemic": true,
          "predef": [         // 列出已知的全局变量,默认为已声明的
              "cc",
              "jsb",
              "ccui"
          ]
      }
      

5.常用npm包推荐

{
      "async": "^2.1.4",
      "ioredis": "^3.1.4",
      "jsonwebtoken": "^7.1.9",
      "lodash": "^4.17.2",
      "log4js": "^1.0.1",
      "moment": "^2.17.1",
      "mysql": "^2.12.0",
      "nanoid": "^0.2.0",
      "request": "^2.79.0",
      "ws": "^3.1.0",
      "xml2js": "^0.4.19"
}

获取更多技术分享,请关注公众号 当下生活瓶

长按或扫描识别二维码

相关文章

网友评论

    本文标题:nodejs 开发环境搭建以及sublime插件推荐

    本文链接:https://www.haomeiwen.com/subject/ceqorftx.html