Node.JS product creation triggers a Stripe outage

Attempting to create a product in stripe has been problematic for me. Every time I make the call with stripe.products.create(), it causes lag, and shortly after my server crashes due to 'JavaScript heap out of memory'.

Here is my approach:

import stripePackage from 'stripe'
const stripe = stripePackage(config.stripe)

// after finding the product in mongoose
stripe.products.create({
    id: product.sku,
    name: product.title,
    type: 'good',
    description: product.description,
    active: product.isAvailable,
    images: product.images,
    package_dimensions: {
        weight: product.shipping.weight * 16,
        length: product.shipping.dimension.length,
        width: product.shipping.dimension.width,
        height: product.shipping.dimension.height
    },
    shippable: true
}).then(stripeProduct => {
    console.log(stripeProduct.id);
    res.json(stripeProduct)
}).catch(err => {
    if (err) {
        console.log(err);
    }
})

CORS configurations

app.use((req, res, next)=> {
  res.header("Access-Control-Allow-Origin", "*")
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, token, auth")
  res.header("Access-Control-Expose-Headers", "token")
  res.header("Access-Control-Allow-Methods", "POST,GET,PUT,DELETE,OPTIONS")
  next()
})

Here is the express.js crash report:

<--- Last few GCs --->

[87147:0x102801e00]    61928 ms: Mark-sweep 1416.8 (1462.3) -> 1416.7 (1446.3) MB, 9502.3 / 0.0 ms  (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 9502 ms) last resort
[87147:0x102801e00]    72192 ms: Mark-sweep 1416.7 (1446.3) -> 1416.7 (1446.3) MB, 10263.3 / 0.0 ms  last resort


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x3ca24589cef1 <JSObject>
    1: encode(aka encode) [/Users/thousight/Projects/Project/node_modules/qs/lib/utils.js:~118] [pc=0x163bec732a95](this=0x3ca245882241 <undefined>,str=0x3ca2458822c1 <true>)
    2: arguments adaptor frame: 2->1
    3: stringify(aka stringify) [/Users/thousight/Projects/Project/node_modules/qs/lib/stringify.js:~32] [pc=0x163bec733b44](this=0x3ca245882241 <undefined>,object=0x3ca24588...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/bin/node]
2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
4: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
5: v8::internal::LoadIC::LoadFullChain(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Smi>) [/usr/local/bin/node]
6: v8::internal::LoadIC::UpdateCaches(v8::internal::LookupIterator*) [/usr/local/bin/node]
7: v8::internal::LoadIC::Load(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>) [/usr/local/bin/node]
8: v8::internal::Runtime_LoadIC_Miss(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
9: 0x163bec5840dd
10: 0x163bec732a95

Can you spot any errors? What do you think caused the server crash? Appreciate your insights.

Node Version: v8.4.0 Stripe-Node Version: v5.8.0

Answer №1

When you use console.log to output the object passed to stripe.products.create(), what do you observe? Is there anything unusual in the output? Are you confident that this is where the problem is occurring?

Update: Specifically, what is the result of this action?

console.log({
  id: product.sku,
  name: product.title,
  type: 'good',
  description: product.description,
  active: product.isAvailable,
  images: product.images,
  package_dimensions: {
    weight: product.shipping.weight * 16,
    length: product.shipping.dimension.length,
    width: product.shipping.dimension.width,
    height: product.shipping.dimension.height
  },
  shippable: true
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"findByIdAndUpdate continues to work successfully even when the request body includes parameters that are not defined in

Referenced from This particular tutorial on MERN stack development... In my mongoose schema, I have defined 4 fields: const mongoose = require('mongoose'); const Schema = mongoose.Schema; let Todo = new Schema({ name: { type: String ...

Efficiency of Promise-based parallel insert queries in MySQL falls short

I have developed a code in Node.js to execute insert queries using Promise.js but unfortunately, I am encountering an exception stating "Duplicate Primary Key" entry. Here is the snippet of the code: var Promise = require("promise"); var mySql = requir ...

Thorax.js bower installation issue

After following the instructions in this guide: https://github.com/walmartlabs/thorax-seed/blob/master/README.md, I ran into an unexpected issue on my Windows machine. When running npm start It seems like bower is doing a lot of work (presumably loading ...

I keep encountering an issue with Nodemailer where it keeps throwing the error message "TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument needs to be a string or.."

The error message is incredibly long, but here is a brief excerpt: TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Object at PassThrough.Writable.write ( ...

Create a custom route variable in Node.js with Express framework

Is there a way to achieve this particular task using express.js? In my express.js application, I have set up a route like so: app.get('/hello', (req, res) => { // Code goes here }); This setup is functional, but I am curious if it is poss ...

Currently using Mongoose and Luxon to showcase the event date, however, I am encountering an issue where the displayed date is one day earlier than expected

Currently, I am working with Mongoose and Luxon to present a date chosen by the user from a form. However, there seems to be an issue where the date is being console logged as one day, but appearing on the page as the previous day. Below is my model setup ...

What distinguishes {key:" "} from {key:" "}, when it comes to JSON files?

I have been working on implementing validation using express Router. The issue I encountered is that when I pass {title:""}, the express-validator does not throw an error. However, when I pass {title:" "}, it works properly. exports.postValidatorCheck = [ ...

How can one ensure that Discord waits for a script to complete running, and how can you prevent Discord from responding until all necessary data has been obtained?

I recently started working with node.js and asynchronous programming, and I'm facing a challenge that has me puzzled. My goal is to create a Discord bot that fetches data from a third-party website. While I can successfully retrieve the data and see i ...

Is sending a stream to a variable the best option, or could there be another solution

Is there a way to pipe stream data to a variable? The writable stream examples mentioned in this documentation include: HTTP requests on the client side HTTP responses on the server side Zlib streams Crypto streams TCP sockets Child process stdin Process ...

What was the reason for node js not functioning properly on identical paths?

When the search route is placed at the top, everything works fine. However, when it is placed at the end, the route that takes ID as a parameter keeps getting called repeatedly in Node. Why does this happen and how can it be resolved? router.get('/se ...

Express: router.route continues processing without sending the request

I've implemented the following code in my Express application: var express = require('express'); // Initializing Express var app = express(); // Creating our app using Express var bodyParser = require(' ...

Extracting Unprocessed Data with Node.js Express

I am currently working with an Express server that handles a login form page: const app = express(); // part A app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.urlencoded()); app.get('/login', ...

How can you move away from using the url:port scheme with socket.io?

Recently, I've been delving into node.js and socket.io, but I'm struggling to eliminate the need to type "url:port" in the browser. Instead, I want users to simply enter the URL and have everything load up, similar to my work-in-progress single p ...

The curious case of Node.JS: The mysterious behaviour of await not waiting

I am currently utilizing a lambda function within AWS to perform certain tasks, and it is essential for the function to retrieve some data from the AWS SSM resource in order to carry out its operations effectively. However, I am encountering difficulties i ...

Having difficulty creating the probot.github app due to an error: The removal of the programmatic API in npm version 8.0.0 causing failure

Currently, I am facing an issue while attempting to set up the probot.github app using the command npx create-probot-app my-first-app which can be found at: . My system is running on the latest node version v19.3.0 with npm version 9.2.0. However, upon exe ...

Step-by-step guide on invoking a recursive function asynchronously in JavaScript

As I delved into the realm of creating a unique Omegle clone using Node.js and Socket.io for educational purposes, I encountered a challenge that has left me scratching my head. The socket ID of clients along with their interests are stored in an array of ...

Inserting multiple rows in MySql using JavaScript through a URL pathUnique: "

Hello there! I am currently attempting to send an array of objects to my MySql Database via an API endpoint. Below is the code snippet from my API: app.get("/orderdetails/add", (req, res) => { const { item__, Qty_Ordered, Unit_Price, ...

Link a YAML file with interfaces in JavaScript

I'm currently learning JavaScript and need to convert a YAML file to an Interface in JavaScript. Here is an example of the YAML file: - provider_name: SEA-AD consortiumn_name: SEA-AD defaults: thumbnail Donors: - id: "https://portal.brain ...

Livereload in Gulp fails to automatically restart the server

How can I make my gulp+livereload server automatically restart and update the page when JS files are changed? Below is a snippet from my gulpfile.js: var gulp = require('gulp'), livereload = require('gulp-livereload'), ...

Perform an update followed by a removal操作

I've been facing a persistent issue that has been troubling me for quite some time now. The setup involves a database in MariaDB (using WAMP) and an API in ExpressJS. Within the database, there are two tables: "menu" and "item," with a foreign key rel ...