A server that performs npm install
and returns a zip file containing the node_modules
.
Build the Docker image:
docker build . -t npm-install
Run the container:
docker run -p 8080:8080 npm-install
Deploy:
gcloud run deploy npm-install \
--source . \
--cpu 8 \
--memory 32Gi \
--no-allow-unauthenticated \
--region europe-west1
Expose the service locally using Cloud Run's local proxy:
gcloud run services proxy npm-install \
--region europe-west1 \
--port 8080
You can now send a POST request to /install
using either a JSON
body or by uploading files using multipart/form-data
.
curl -X POST http://localhost:8080/install \
-F "package.json=@example/package.json" \
-F "package-lock.json=@example/package-lock.json" \
--output node_modules.zip
The package-lock.json
field is optional.
curl -X POST http://localhost:8080/install \
-H "Content-Type: application/json" \
-d '{
"package.json": "{\"name\":\"test-package\",\"dependencies\":{\"express\":\"^4.17.1\"}}"
}' \
--output node_modules.zip
The server will:
- Create a temporary directory
- Write the package files
- Run
npm install
(ornpm ci
if package-lock.json is provided) - Zip the resulting
node_modules
directory - Stream the zip file back in the response