第二章、nodejs服务端开发--前准备

一、配置淘宝镜像

1、npm临时使用淘宝镜像安装依赖包

npm i -g express --registry https://registry.npm.taobao.org

2、npm持久使用淘宝镜像安装依赖包

npm config set registry https://registry.npm.taobao.org
npm i -g express

3、还原npm原始包

npm config set registry https://registry.npmjs.org/

二、一些常用设置

1、查看npm

npm config ls

2、设置:主要是设置cacheprefix

npm cofig set cache "D:\Program Files\nodejs\node_cache"
npm cofig set prefix "D:\Program Files\nodejs\node_global"

三、插件

1、nodemon

nodemon是一种工具,可以自动检测到目录中的文件更改时通过重新启动应用程序来调试基于node.js的应用程序。

安装

npm install -g nodemon
//或
npm install --save-dev nodemon

使用

传统的方法,我们使用node app.js命令,程序将启动。其实,我们刚才下载的nodemon工具也可以用来启动。

nodemon   ./main.js // 启动node服务

 

nodemon ./main.js localhost 6677 // 在本地6677端口启动node服务

 

"start": "ts-node -r tsconfig-paths/register nodemon src/main.ts",

延迟重启

 

nodemon -delay10 main.js

nodemon --delay 2.5 server.js

nodemon --delay 2500ms server.js

这个就类似于js函数中的函数节流,只在最后一次更改的文件往后延迟重启.避免了短时间多次重启的局面.

配置文件

nodemon支持本地和全局配置文件。这些通常是命名的nodemon.json,可以位于当前工作目录或主目录中。可以使用该--config <file>选项指定备用本地配置文件。

 

{
  "verbose": true,
  "ignore": ["*.test.js", "fixtures/*"],
  "execMap": {
    "rb": "ruby",
    "pde": "processing --sketch={{pwd}} --run"
  }
}

2、AnyWhere

AnyWhere是一款随启随用的静态文件服务器,可以随时随地将你的当前目录变成一个静态文件服务器的根目录。

安装:

npm install anywhere -g

使用:

$ anywhere
// or with port
$ anywhere -p 8000
// or start it but silent(don't open browser)
$ anywhere -s
// or with hostname
$ anywhere -h localhost -p 8888
// or with folder
$ anywhere -d ~/git/anywhere
// or enable html5 history
$ anywhere -f /index.html

使用帮助:

$ anywhere --help
Usage:
  anywhere --help // print help information
  anywhere // 8000 as default port, current folder as root
  anywhere 8888 // 8888 as port
  anywhere -p 8989 // 8989 as port
  anywhere -s // don't open browser
  anywhere -h localhost // localhost as hostname
  anywhere -d /home // /home as root
  anywhere -f /index.html  // Enable html5 history,the index is /index.html
http://localhost:8000

执行命令后,默认浏览器将为您自动打开主页。

3、lodash 

Lodash是一个著名的javascript原生库,不需要引入其他第三方依赖。是一个意在提高开发者效率,提高JS原生方法性能的JS库。通过使用数组,数字,对象,字符串等方法,Lodash使JavaScript变得更简单。

npm i lodash --save --registry=https://registry.npm.taobao.org
var _ = require('lodash');//nodejs中调用

 

手册:

nodejs官网  

ECMAScript 6 入门

JavaScript 标准参考教程(alpha)

CommonJS规范 -- JavaScript 标准参考教程(alpha)

lodash

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值