Skip to content

as-a-service/npm-install

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm install as a service

A server that performs npm install and returns a zip file containing the node_modules.

Building and Running with Docker

Build the Docker image:

docker build . -t npm-install

Run the container:

docker run -p 8080:8080 npm-install

Deploying to Google Cloud Run and proxying locally

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

Usage

You can now send a POST request to /install using either a JSON body or by uploading files using multipart/form-data.

Using local files (recommended)

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.

Using JSON body

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:

  1. Create a temporary directory
  2. Write the package files
  3. Run npm install (or npm ci if package-lock.json is provided)
  4. Zip the resulting node_modules directory
  5. Stream the zip file back in the response

About

Let's npm install as fast as possible

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published