1

I'm getting an error when trying to stringify a global variable in sails: TypeError: converting circular structure to JSON.

I know what the error means, but the question is, what's happening that's causing there to be a circular reference. And, why does it happen to my custom variable?

Then the next question is: how can I stringify the object the way I created it in globals.js?

In config/globals.js:

module.exports.globals = {
    mystuff: {
        Url: "http://localhost:8080",
        APIKey: "2bb67717b99a37e92e59003f93625c9b"
    }
}

In a hook initialize:

module.exports = function (sails) { 
   return {

        initialize: function(cb) {
           var str = JSON.stringify(sails.config.globals.mystuff);
        }
   }
}
eyn
  • 778
  • 2
  • 10
  • 21

1 Answers1

0

This helped identify circular culprits: Detecting and fixing circular references in JavaScript

Another portion of the app was injecting objects into the globals.

Community
  • 1
  • 1
eyn
  • 778
  • 2
  • 10
  • 21