What is wrong with this YAML file for Node.js?

Hello,
This is a runner file for a Node.js project. What is the problem with this file?

stages:
  - build
  - deploy
cache:
  paths:
    - node_modules/
build-project:
  stage: build
  script:
    - rm -rf node_modules
    - mkdir -p node_modules/
    - rm -rf /mnt/SOURCE/project
    - cd /mnt/SOURCE/
    - git clone URL
  tags: 
    - backend
    - project
deploy-project:
  stage: deploy
  script:
    - cd /mnt/YAML
    - docker compose up -d project
  tags: 
    - backend
    - project

Does the rm -rf node_modules line cause the modules to be downloaded again every time the container is started? Should I remove this line?

Cheers.

I am not specialist in Node.js but I don’t see anything wrong with this file.

What is doing during deployment is getting rid of whatever was deployed before and bringing down the latest code for deployment. Which the correct thing to do. Never leave any code behind (nuke the code) before deployment.

No. ‘rm -rf node_modules’ will not help you.

‘git clone URL’ is downloading the latest source code.

What you can do is create a run stage in this file, and run only that stage or
Open a command prompt and run this:

cd /mnt/YAML
node your_script.js
1 Like

Hello,
Thank you so much for your reply.
If I delete the node_modules folder, then whenever I run npm install it will download all the modules. If I don’t delete the node_modules folder and run npm install, will there be any problem?

If you don’t delete node_modules, and run npm install. The program will notice the modules are already there and it will download nothing.

Give it a try with the two options and watch the command output prompt.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.