I am trying to integrate the mailchimp OAuth plugin for node (https://github.com/gomfunkel/node-mailchimp/) and I keep getting an EADDRINUSE error and I am not sure what the issue is. I know what the error means I just don't know how to stop it.
My express server is running on port 3000. The mailchimp class evidently wants to spawn a server - it defaults to port 8100. I have tried changing both of these ports to no avail. What could be the issue?
Here's the route code I am using:
exports.test = function(req, res){
var MailChimpOAuth = require('mailchimp').MailChimpOAuth;
var MailChimpAPI = require('mailchimp').MailChimpAPI;
var options = {
clientId: '00000000',
clientSecret: 'abcdefghijklmnop',
serverUri: 'http://localhost',
redirectUri: 'http://localhost',
};
var oauth = new MailChimpOAuth(options);
Now my initial request works and any subsequent ones cause the error - probably encountering the already spawned server. Is that a bug in the mailchimp class that is should see if it already spawned?
From what I can tell, you're creating a new MailChimpOAuth
on every request, so when your second request rolls around, you've already got a server listening on 8100.
You need to do all that setup stuff once at initialization and, in your request handler, refer to the already instantiated MailChimpOAuth
instance.
As a general rule, if you find yourself doing a require(...)
in code that runs more than once, your logic needs rethinking.