'React + flask: how to run API using command line

I am using Yarn in a react and flask api building project. I am new to api building and react. I have introduced a command as "start-api" in the react's package.json file to start the api in a local host server. But when I use the command in the command prompt as "yarn start-api", it shows command not found error. Below is my package.json file code, flask/python code and cmd picture.

package.json

{
  "name": "flask-api",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "react-scripts start",
    "start-api": "cd api && venv/bin/flask run --no-debugger",
    "build": "react-scripts build",
    "test": "echo \"Error: no test specified\" && exit 1",
    "eject": "react-scripts eject"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^16.13.1"
  },
  "proxy": "http://localhost:5000"
}

flask/python code:

import time 
from flask import Flask

app = Flask(__name__)

@app.route('/time')
def get_current_time():
    return {'time': time.time()}

if __name__ == '__main__':
    # app.debug = True
    #app.run()
    app.run(debug = True)

command line output:
[command line error output][1]

With that my react app is in a folder named "react-flask-app" in the root, while my api is in an "api" named folder in the root. Help will be appreciated because I am a beginner. 


  


Solution 1:[1]

I run it using npm.

npm run start-api

This works for me everytime. Let me know if I am doing something wrong.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gothram