skip to Main Content

I am very new to all technologies used in the project that I am trying to run and work on in the future (docker, node.js, etc.).

I am trying to run node server by calling docker-compose up --build. I am running the server from my Win 10 cmd, running the server from linux is confirmed working.

I am getting

> [email protected] start /usr/src/server
backend | > nodemon index.js
backend |
backend | /usr/src/server/node_modules/.bin/nodemon: 1: /usr/src/server/node_modules/.bin/nodemon: ../nodemon/bin/nodemon.js: not found
backend | npm ERR! file sh
backend | npm ERR! code ELIFECYCLE
backend | npm ERR! errno ENOENT
backend | npm ERR! syscall spawn
backend | npm ERR! [email protected] start: `nodemon index.js `
backend | npm ERR! spawn ENOENT
backend | npm ERR!
backend | npm ERR! Failed at the [email protected] start script.
backend | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
backend |
backend | npm ERR! A complete log of this run can be found in:
backend | npm ERR!     /root/.npm/_logs/2020-10-11T13_03_10_909Z-debug.log

What I tried and concluded (googling everywhere for over a week):

  1. Preinstalling nodemon in package.json, installing globally
  2. Finding out that there indeed is nodemon.js inside node_modules, I just cant seem to access it( with cd for example)
  3. RUN npm install --save nodemon results in npm ERR! File exists: /usr/src/server/node_modules/.bin/nodemon
  4. Many other solutions found on stackoverflow resulted in the not found or File exists error.
  5. printenv prints: npm_package_dependencies_nodemon=^1.19.4 (not sure if it means something)
  6. I tried installing nodemon globally after cleaning all docker images and running the command fresh

In my conclusion: nodemon is installed in modules, but I cant access it

package.json:

{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "nodemon index.js "
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcrypt-nodejs": "0.0.3",
    "body-parser": "^1.19.0",
    "compression": "^1.7.4",
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "jsonwebtoken": "^8.5.1",
    "knex": "^0.20.2",
    "knex-list-db-table": "^0.2.0",
    "morgan": "^1.9.1",
    "multer": "^1.4.2",
    "nodemon": "^1.19.4",
    "path": "^0.12.7",
    "pg": "^7.12.1",
    "redis": "^2.8.0",
    "uuid": "^3.3.3"
  }
}

Dockerfile:

FROM node:8.11.3

WORKDIR /usr/src/server

COPY ./ ./

RUN npm install

EXPOSE 80
# CMD ["/bin/bash"]
CMD [ "npm", "start" ]

docker.compose:

version: '3.6'

services:
  # Backend API
  knizka-server:
    container_name: backend
    build: ./
    command: npm start
    working_dir: /usr/src/server
    environment:
      POSTGRES_URI: postgres://test:pswd@postgres:5432/server-docker
      REDIS_URI: redis://redis:6379
    links:
      - postgres
      - redis
    ports:
      - '80:80'
    volumes:
      - ./:/usr/src/server

  #postgres
  postgres:
    environment:
      POSTGRES_USER: test
      POSTGRES_PASSWORD: pswd
      POSTGRES_DB: server-docker
      POSTGRES_HOST: postgres
    build: ./postgres
    ports:
      - '5432:5432'

  #redis
  redis:
    image: redis
    ports:
      - '6379:6379'

2

Answers


  1. Chosen as BEST ANSWER

    I dont know which thing fixed it, but I tried all of those things and eventually I ran nodemon sucesfully:

    • use node 10
    • delete node_modules
    • delete package-lock
    • npm install

  2. In docker-compose file, can you change the volumes for knizka-server like the following?

    knizka-server: 
         ...
         volumes:
              - ./:/usr/src/server
              - /usr/src/server/node_modules
    

    And then build it again.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search