Home > Enterprise >  Node.js install Python dependencies from within package.json
Node.js install Python dependencies from within package.json

Time:05-02

I'm building a Node.JS project that uses both Python and NPM dependency modules.

The Node.JS modules are located within package.json and the python dependencies are inside a file requirements.txt.

I would like to install all the dependency modules (Python and Node.JS) from within package.json by running npm install.

Is this possible and how?

Thanks in advance!

The files look like below.

package.json:


{
  "name": "app",
  "version": "1.0.0",
  "description": "Trial app",
  "main": "bin/index.js",
  "scripts": {
    "dev": "npm install",
    "start": "node app.js",
    "test": "jest --forceExit "
  },
  "keywords": [
    "AI",
    "Blockchain",
    "Decentralized"
  ],
  "dependencies": {
    "peerjs": "^1.3.2",
    "redis": "^3.1.2",
    "socket.io": "^4.1.2",
    "socket.io-client": "^4.1.2",
    "wrtc": "^0.4.7"
  },
  "devDependencies": {
    "@babel/core": "^7.16.7",
    "supertest": "^6.1.6"
  }
}

requirements.txt:


Django==2.2.21
djangorestframework==3.7.7
django-rest-swagger
coreapi

CodePudding user response:

You can define Commands to run within the "scripts" section of your package.json. Every script in there can be run with npm run [scriptname].

So you could do (&& runs another command after the first one)

"scripts": {
    "install": "npm install && pip -r requirements.txt",
    "dev": "npm install",
    "start": "node app.js",
    "test": "jest --forceExit "
  }

And run npm run install

CodePudding user response:

Replace "dev": "npm install" with "dev": "npm install & pip install"

  • Related