0

I'm studying a React project and i have to say that so far i have seen just script with "start": "nodemon app.js". I'm using Windows os.

But now i try to start this node project that has this script part:

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "if [[ $NODE_ENV == 'development' ]]; then nodemon --experimental-modules; else node --experimental-modules src/index.js; fi",
    "dev": "env NODE_ENV=development nodemon  --ignore './tmp/' --experimental-modules ./src/index.js",
    "lint": "eslint \"src/**/*.js\" --config \"../../.eslintrc\"",
    "migration:up": "node -r esm ./node_modules/.bin/sequelize db:migrate",
    "migration:down": "node -r esm ./node_modules/.bin/sequelize db:migrate:undo",
    "seed": "node -r esm node_modules/.bin/sequelize db:seed:all"
  },

And I don't know how to start it and why the developer make the start part so complicated. In fact, if i try to write the command npm start it give me the error:

> if [[ $NODE_ENV == 'development' ]]; then nodemon --experimental-modules; else node --experimental-modules src/index.js; fi

$NODE_ENV not expected.
npm ERR! code ELIFECYCLE

I search for thi NODE_ENV variable but it is only mentioned in this file Dockerfile

FROM node:14

RUN apt-get update && apt-get -y install vim

ARG NODE_ENV
WORKDIR /usr/src/app
COPY package.json ./
RUN npm i 
#--quiet --production
COPY . .

CMD ["start"]
ENTRYPOINT ["npm"]

How can I start the program? And why this start command is so different?

July
  • 516
  • 1
  • 7
  • 25
  • Are you using Windows OS? – Mic Fung May 21 '21 at 22:23
  • yes, I am @MicFung – July May 21 '21 at 22:30
  • 1
    So you cannot run this as it contains some shell logic - `if.. else.. fi`. Do you have WSL (the ubuntu linux) installed on your Windows? – Mic Fung May 21 '21 at 22:32
  • 1
    If you want to install WSL, here is the guide https://learn.microsoft.com/en-us/windows/wsl/install-win10. If you need to start the project urgently, you can just run the command `node --experimental-modules src/index.js` without `npm start` – Mic Fung May 21 '21 at 22:34
  • 1
    The starting command is different because the one who develop it want to choose which command to start the server when node environment is different. For development, he wants to use `nodemon`. In other env, he want to use `node`. `nodemon` can restart your server automatically after you save your changes without stop and start the server manually. This is the intention of the start command. – Mic Fung May 21 '21 at 22:38

0 Answers0