# Create Service profiles for nodejs microservices - hope is helps

**URL:** <https://linkerd.buoyant.io/t/create-service-profiles-for-nodejs-microservices-hope-is-helps/355>\
**Category:** Linkerd General Discussion\
**Tags:** metrics\
**Created:** [January 9, 2024, 3:54pm UTC](https://linkerd.buoyant.io/t/create-service-profiles-for-nodejs-microservices-hope-is-helps/355 "2024-01-09T15:54:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![glzmn](https://avatars.discourse-cdn.com/v4/letter/g/cc9497/32.png) [@glzmn](https://linkerd.buoyant.io/u/glzmn)\
**Post date:** [January 9, 2024, 3:54pm UTC](https://linkerd.buoyant.io/t/create-service-profiles-for-nodejs-microservices-hope-is-helps/355/1 "2024-01-09T15:54:19Z")

</div>

```auto
#!/bin/bash

# Define the directory of your Node.js project
if [-z "$1"]; then
    echo "Usage: $0 <project_directory>"
    exit 1
fi
project_directory=$1

# Use find to locate all JavaScript files in the project containing @Controller
js_files=$(find "$project_directory" -type f -name "*.ts" -exec grep -l '@Controller' {} \;)

# Loop through each file with @Controller and use grep to extract URLs from @Get, @Post, etc.
for file in $js_files; do
    # echo "Extracting path prefixes and suffixes from $file..."

    # Extract path prefix within the @Controller decorator
    controller_paths=($(awk -F"'" '/@Controller/{print $2}' $file))
    http_methods=($(awk -F"'" '/@(Get|Post|Put|Delete)/{gsub(/.*@/, "", $0); gsub(/\(.*/, "", $0); print toupper($0)}' "$file"))
    http_suffixes=($(awk -F"'" '/@(Get|Post|Put|Delete)/{gsub(/.*@/, "", $2);gsub(/".*/, "", $2);print $2}' "$file"))

  for controller_path in "${controller_paths[@]}"; do
    # echo "Controller Path: $controller_path"
      # echo "HTTP Methods: $http_methods"
      if [-n "$http_suffixes"]; then
        for suffix in "${http_suffixes[@]}"; do
            echo "- condition:"
            echo " method: $http_methods"
            full_path="$controller_path$suffix"
            echo " pathRegex: $full_path"
            echo " name: $http_methods $suffix"
        done
      else
            echo "- condition:"
            echo " method: $http_methods"
            full_path="$controller_path/"
            echo " pathRegex: $full_path"
            echo " name: $http_methods $full_path"
      fi
  done
done

```

---

<div class="post-metadata">

**Author:** ![william](https://yyz1.discourse-cdn.com/flex029/user_avatar/linkerd.buoyant.io/william/32/5_2.png) [@william](https://linkerd.buoyant.io/u/william)\
**Post date:** [January 10, 2024, 3:48pm UTC](https://linkerd.buoyant.io/t/create-service-profiles-for-nodejs-microservices-hope-is-helps/355/2 "2024-01-10T15:48:16Z")

</div>

Thanks for posting this @glzmn!
