I get the following error while trying to access SharePoint from nodejs
events.js:71 throw arguments[1]; // Unhandled 'error' event ^ Error: connect ECONNREFUSED at errnoException (net.js:769:11) at Object.afterConnect [as oncomplete] (net.js:760:19)
below is the code
var SP = require('sharepoint'),
site = //url,
username = //username,
password = //password;
var client = new SP.RestService(site),
contacts = client.list('Contacts');
var showResponse = function (err, data) {
console.log(data);
}
client.signin(username, password, function () {
// At this point, authentication is complete,
// so we can do requests.
// Example request: Get list items
// showResponse is used as callback function
contacts.get(showResponse)
});
The important part of that error message is ECONNREFUSED, meaning the connection was refused right away. That means it never got to the point of checking your username and password or anything.
You should double-check your value for site. Maybe the server is running on a different port or you have a typo in that value.
Depending on the SharePoint module implementation you've to pass the entire url addressing the REST service.
In SharePoint 2010 the entire REST Service url should look like this
http:// %%SharePointSiteUrl%% /_vti_bin/ListData.svc
You should double check the outgoing requests direction SharePoint by using fiddler or an alternative HTTP watcher.