欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

5.npm scripts 使用指南

程序员文章站 2022-03-03 18:53:37
...

简单介绍

scripts里面的
"start": "node app"
npm run start 相当于 node app

{
  "name": "5-npm-scripts",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "dependencies": {},
  "devDependencies": {
    "nodemon": "^1.9.2"
  },
  "scripts": {
    "start": "node app",
    "dev": "nodemon app",
    "test": "node test",
    "test-watch": "nodemon test"
  },
  "author": "",
  "license": "ISC"
}

更加详细的介绍,建议看阮一峰的scripts介绍

npm scripts 使用指南

nodemon

这个可以监控js变化

eg

app.js

'use strict';
var math = require('./math');
var value = math.add(5, 6);
console.log(value);

math.js

exports.add = function(a, b) {
  return a + b;
}

exports.subtract = function(a, b) {
  return a - b;
}

exports.multiply = function(a, b) {
  return a * b;
}

test.js

'use strict';

var assert = require('assert');

var math = require('./math');

assert(math.add(3, 4) === 7);
assert(math.subtract(3, 4) === -1);
assert(math.multiply(3, 4) === 12);

console.log("all tests passed!");