初学node.js,安装nodemon,学习debug模式,安装cpu-stat
1.运行node 文件
node .\01.js
文件内容
console.log('aaaa');
2.因为每次更新文件都需要重新,所以安装nodemon
npm i -g nodemon
就会自动更新内容
3.添加debug,选择debug模式,然后选择add ,如图
4.安装cpu
npm i cpu-stat -S
5.模块
总共分为三种:
1.内建模块
const os = require('os');
const mem = os.freemem() / os.totalmem() *100
console.log(`内存占用率:${mem}%`)
2.第三方模块 需要安装cpu-stat // npm i cpu-stat -S
const cpuStat = require('cpu-stat')
cpuStat.usagePercent((err,percent)=>{
console.log(`cpu占用率:${percent}`)
})
3.自定义模块
const conf = require('./conf');
console.log(conf);
conf.js 文件如下:
module.exports = {
url:'mongodb://localhost:27017',
dbname:'test',
user:'admin',
password:'123'
};
const {rmbToDollar} = require('./currency')(6);
console.log(rmbToDollar(100));
currency.js 文件如下:
let rate;
function rmbToDollar(rmb){
return rmb/rate;
}
module.exports= function(r){
rate = r;
return {rmbToDollar};
}
本文来自博客园,作者:quitpoison,转载请注明原文链接:https://www.cnblogs.com/quitpoison/p/10507713.html