In node using modules. how to change require to import for stripe

22 Views Asked by At

In my node application iam usign the modules system which i specified in my package file

 {
  "name": "ccbill-node-integration",
  "version": "1.0.0",
  "description": "node integration for ccbill",
  "main": "ppayproc1.js",
  "type": "module",
.....

this allows me to declare somnething like import express from ... instead of require.

iam working on stripe integration. as per their docs

const stripe = require('stripe')('sk_test_51_secretkey');

whats the equivalent of this using import.

i was thingking i can do something like

 import stripe from 'stripe';
    stripe('sk_test_51_secretkey');

will this be considered valid ?

thank you

1

There are 1 best solutions below

0
SChristie On

Try the following, replacing your_secret_key with the key created via Stripes dashboard.

import Stripe from 'stripe';
const stripe = new Stripe('your_secret_key')