DEV Community

Cover image for Nodejs cloud function deployment with private npm packages
Kanthaliya
Kanthaliya

Posted on • Edited on

2

Nodejs cloud function deployment with private npm packages

Cloud Functions is an event-driven serverless compute platform from Google. You can run your code locally or in the cloud without having to provision servers. There are many ways to run nodejs application on cloud function. we are going to look for zip upload and deploy code from terminal.

On Google cloud platform select cloud function and create function.
Alt Text

Fill the required information

  1. Name - function name for your program.
  2. Memory allocated - as required by function processing.
  3. Trigger - select Http
  4. Source code - zip upload.
  5. Runtime - nodejs 10
  6. Function to execute - It is a name of a function exported by the module specified in the directory with source code.
  7. Check Advance Options if you want more control. Alt Text

and finally upload a zipped nodejs application.

To deploy nodejs application with private npm package, include .npmrc file at root level -

//npm.private.com/:_authToken="<token>"
@ng-test:registry=https://npm.private.com/ 
Enter fullscreen mode Exit fullscreen mode

you can read private npm package auth token from ~./npmrc or login with npm login --registry=https://registry.company-name.npme.io and npm token list.

In package.json add private package name in dependencies and Google functions-framework in dev dependencies.

{
    "name": "notification-service",
    "version": "1.0.0",
    "description": "Notification Service",
    "main": "index.js",
    "author": "Pritesh Kanthaliya",
    "license": "UNLICENSED",
    "scripts": {
        "start": "npx @google-cloud/functions-framework --target=notificationService",
        "deploy": "npx gcloud functions deploy notificationService --runtime nodejs10 --trigger-http",
    },
    "dependencies": {
        "@ng-test/hello-world": "1.0.0",
    },
    "devDependencies": {
        "@google-cloud/functions-framework": "~1.5.1",
    }
}
Enter fullscreen mode Exit fullscreen mode

With npm start you can run nodejs application at local machine and test. With npm deploy you can deploy your code on Google cloud function. If a cloud function is already present with the same name, it overrides the current one else it would create a new one.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay