nodejs生产环境配置及优化

1.清除多余包
npm prune --production

2.使用代码优化
a.grunt-contrib-uglify,精简代码
b.去掉所有console.*
c.使用grunt-contrib-jshint检测代码

3.尽可能使用strict mode
文件中使用'use strict'或者命令node --use_strict

4.内存优化、垃圾回收 v8-options
64位V8是1.5G内存上限,32位0.7G,通过下面参数可以修改
--max_new_space_size (max size of the new generation (in kBytes))
type: int default: 0
--max_old_space_size (max size of the old generation (in Mbytes))
type: int default: 0
--max_executable_size (max size of executable memory (in Mbytes))
type: int default: 0
--gc_global (always perform global GCs)
type: bool default: false
--gc_interval (garbage collect after <n> allocations)
type: int default: -1
node --use_strict --max_old_space_size=2000 --max_executable_size=2000 --gc_global --gc_interval=200 app.js
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值