Problem with "require" in custom module

Still no expert on custom modules but trying my hardest!!

Decided to take a quick look at an Paypal IPN solution for Node after noticing an npm “paypal-ipn”

So i installed with

npm install paypal-ipn

I can see it installed:

image
typing into terminal

npm ls

shows it installed:

image

and checking package-lock.json correctly shows its presence and version

image

however when i try to use it

image

I get a not found error

Anyone any ideas where things are going wrong?

If you are using a Docker development environment with Node try reinstalling all packages

node local server, made not difference

const ipn = require('paypal-ipn);

module.exports = {
    yourIPNfunction: function(options) {
        //options contains the input data you use in the UI for this SC action. You will probably pass the params that the IPN verify function needs via a binding in the UI. 
        ipn.verify(params, function callback(err, msg) {
            if (err) {
                console.error(err);
            } else {
               // Do stuff with original params here
               if (params.payment_status == 'Completed') {
               // Payment has been confirmed as completed, return something
                   return true
               }
               else { 
                   return false
               }
            }
        });
    }
}

In the hsjon file the action key needs to have the value yourIPNfunction

Out of curiosity I did a test:
Wappler 4.9.1
MacOS Monterey
Local docker + node

I installed npm paypal-ipn from the wappler terminal
when i try to run the script it returns the same error as you.

I tried to reinstall the node modules but it still doesn’t work

In my case the solution is this:

In the Docker desktop application window go to Containers and then click on CLI,

from here a terminal window will open, launch the command npm install paypal-ipn and finally restart all Docker services

now the script does not return any errors

Wappler 4.9.1
MacOS Monterey
Local node

I installed npm paypal-ipn from the wappler terminal

No problems found

Thanks a lot for the code tidy up @JonL , much appreciated. You are a great help to this community. Unfortunately the “require” issue remained HOWEVER also thanks to @Pier, your solution worked perfectly i.e. installing npm via docker container. Starting to wonder is all it may have needed was a simple deploy to local target?, i can remember if i did or not

If you are using a local server an npm install in the project folder and a require should be more than enough. Installing the module in a docker container shouldn’t make a difference at all given that you are not using docker to develop your app.

Something is wrong here.

Yes, me! Thought my testbed was set up to use inbuild node server (that’s my normal setup) but for some strange reason i had set this one up in docker local.
Only when I saw Pier’s post did I check and realise what i had done
My Bad

1 Like