Serverless functions for nodejs + MySQL?

Hi there,

I want to develop a small application and thought of using DO serverless functions.

The function is very small and will be activated by an HTTP request, about once a month. Therefore I think creating a full App for will be an overkill…

What I need to achieve:

  1. A POST an HTTP request from Apify will send some data to DO function.
  2. The function to process data, then update a MySQL DB hosted on DO
  3. The same function or another one is to update my WordPress website using WP API (hosted on a DO droplet)
  4. This will run on Nodejs and the code requires a few NPM packages inits

Will DO serverless functions be up to the task? Or do I still need to lunch a full App + Express for this?

Can I requier NPM pachages? Can I connect to the MySQL DB? Can I connect the MySQL DB using DO native connector like with the Apps or do I still needs to use some NPM package like sequelize.js?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This comment has been deleted

    Matt Welke
    DigitalOcean Employee
    DigitalOcean Employee badge
    April 16, 2023

    You should be able to accomplish this with DO Functions. It sounds like you will need to accomplish two main things.

    1. Update data in managed MySQL from a function
    2. Use the WordPress API from a function

    As you note, you can implement this using a single function or a function per use case. The idiomatic approach with FaaS is to use a function for each use case.

    For use case #1, we have an example repo showing how to connect to MySQL. You’ll notice that it uses a package.json file to specify NPM dependencies to use, like for the MySQL library. For more info on dependencies in Node.js functions, see our docs.

    For use case #2, we don’t have an example showing how to use the WordPress API, but you could use our existing examples to build this function. You may be able to find SDK libraries for this API on NPM. If not, you’d use your preferred HTTP library to make these requests yourself.

    Concerning networking best practices, because we don’t yet support VPC connections between droplets, App Platform, and Functions, you’ll want to secure your connections between these products using other techniques, like Trusted Sources and WordPress API credentials. That way, when your functions connect to MySQL and to the WordPress API, they do so as securely as possible since the traffic would be traversing the public. For the same reason, ensure you’re using HTTPS instead of HTTP for this traffic.

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Get our biweekly newsletter

    Sign up for Infrastructure as a Newsletter.

    Hollie's Hub for Good

    Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

    Become a contributor

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    Welcome to the developer cloud

    DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

    Learn more
    DigitalOcean Cloud Control Panel