npm、模块暴露,小知识点区别

  • --save-dev与--save的区别

      npm install xxx  --save-dev 
    

是指将包信息添加到 package.json 里的 devDependencies节点,表示开发时依赖的包。

	npm install xxx  --save

是指将包信息添加到 package.json 里的dependencies节点,表示发布时依赖的包。

  • module.exports 与 exports 的区别
    exports是module.exports的辅助方法。你的模块最终返回module.exports给调用者,而不是exports,exports所做的事情是收集属性。如果module.exports当前没有任何属性的话,exports会把这些属性赋予module.exports,如果module.exports有属性的话,exports中所有的东西将会被忽略。

      //lianxi.js
      module.exports = 'hello';
      exports.name = function(){
          console.log('hello world');
      };
      
      ///另一个文件
      var lianxi = require('./lianxi.js');
      lianxi.name();
    

将不会返回hello world;

如果你想你的模块是一个特定的类型就用Module.exports。如果你想的模块是一个典型的“实例化对象”就用exports。

  • nodemon
    这个库是专门调试时候使用的,它会自动检测 node.js 代码的改动,然后帮你自动重启应用。在调试时可以完全用 nodemon 命令代替 node 命令。

  • 安装

     	 $ npm install -g nodemon
    
  • 运行

         $ nodemon xxx.js
原文地址:https://www.cnblogs.com/yehui-mmd/p/7397903.html