node.js - node start fejl i Windows

Indlæg af Hanne Mølgaard Plasc

Problem



Windows MEVN-stakprojekt
jeg har npm start terminal output:


$ npm start

> nodejs-starter@1.0.0 start C:final-dipdiplom-master
> SECRET=diplom nodemon index.js

"SECRET" is not internal or external
command, executable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nodejs-starter@1.0.0 start: `SECRET=diplom nodemon index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nodejs-starter@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:UsersAdminAppDataRoaming
pm-cache\_logs2018-05-04T10\_33\_19\_073Z-debug.log





kode i package.json:


{
  "name": "nodejs-starter",
  "version": "1.0.0",
  "description": "A boilerplate for NodeJS web servers",
  "main": "index.js",
  "scripts": {
    "start": "SECRET=diplom nodemon index.js",
    "init": "node ./controllers/init",
    "debug": "cross-env PORT=3333 SECRET=GREEN\_BUS nodemon --inspect index.js"
  },
  "keywords": [],
  "author": "Almat Ybray",
  "license": "MIT",
  "devDependencies": {
    "eslint": "^4.14.0",
    "nodemon": "^1.14.7"
  },
  "dependencies": {
    "async": "^2.6.0",
    "body-parser": "^1.18.2",
    "cookie-parser": "^1.4.3",
    "cors": "^2.8.4",
    "express": "^4.16.2",
    "express-jwt": "^5.3.1",
    "express-validator": "^5.0.3",
    "helmet": "^3.9.0",
    "jsonwebtoken": "^8.2.0",
    "mongoose": "^5.0.0-rc1",
    "morgan": "^1.9.0",
    "multer": "^1.3.0",
    "passport": "^0.4.0",
    "passport-local": "^1.0.0",
    "socket.io": "^2.0.4"
  }
}

Bedste reference


Du mangler cross-env til dit start script. Skift din package.json til:


{
  "scripts": {
    "start": "cross-env SECRET=diplom nodemon index.js"
  }
}


Den bruges allerede i debug scriptet.


BEMÆRK Det er heller ikke en del af afhængigheder, så det skal tilføjes via npm i cross-env --save.