0
votes

I'm following this tutorials for my first TDD project: https://medium.com/developer-circles-lusaka/how-to-write-an-express-js-server-using-test-driven-development-921dc55aec07

I have install all the required dependency and my package.json file looks like below.

{
  "name": "lms_webapi",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "babel src -d dist --source-maps",
    "serve": "NODE_ENV=production node dist/index.js",
    "start": "NODE_ENV=development babel-node src/index.js",
    "dev": "DEBUG=server:debug NODE_ENV=development nodemon src/index.js --exec babel-node",
    "test": "DEBUG=server:debug NODE_ENV=test mocha --require babel-core/register --reporter spec --exit   tests/ --exec babel-node",
    "test:watch": "DEBUG=server:debug NODE_ENV=development mocha  --require babel-core/register --watch --reporter  spec   tests/ --exec babel-node",
    "eslint": "eslint src/**/*.js --ignore-pattern \"node_modules/\""
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel-cli": "^6.26.0",
    "babel-preset-node8": "^1.2.0",
    "chai": "^4.2.0",
    "config": "^3.3.1",
    "debug": "^4.1.1",
    "express": "^4.17.1",
    "mocha": "^7.1.1",
    "mongoose": "^5.9.7",
    "supertest": "^4.0.2"
  },
  "babel": {
    "presets": [
      "node8"
    ]
  },
  "engines": {
    "node": ">=8"
  },
  "eslintConfig": {
    "plugins": [
      "node"
    ],
    "extends": [
      "eslint:recommended",
      "plugin:node/recommended"
    ],
    "rules": {
      "node/no-unsupported-features/es-syntax": 0,
      "node/no-unsupported-features/es-builtins": 0
    },
    "env": {
      "node": true,
      "es6": true
    },
    "parserOptions": {
      "sourceType": "module",
      "ecmaVersion": 2018
    }
  }
}

after running the command npm run dev from terminal, I got the following error.

[email protected] dev E:\Test\LMS_WebAPI

DEBUG=server:debug NODE_ENV=development nodemon src/index.js --exec babel-node Der command "DEBUG" is either false or not found. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] dev: DEBUG=server:debug NODE_ENV=development nodemon src/index.js --exec babel-node npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Your help will be highly appreciated. Thank you!

1

1 Answers

1
votes

The dev-script fails because it tries to look for the DEBUG command instead of setting the environment variable. This tells us that you're probably on a windows machine. Hence, you need can adjust setting the env-variables as follows:

...
"scripts": {
    ...
    "dev": "set DEBUG=server:debug && set NODE_ENV=development && nodemon src/index.js --exec babel-node",
  },
...