0

I'm developing a script in Node.js that needs to send multiple http requests. I'm really familiar with the way Angular's $http service works. I like the use of promises and overall syntax, I know its advantages and disadvantages etc.

Can I in any way use Angular $http service in a Node.js app? I hope this doesn't sound too silly.

4 Answers 4

3

For promises like the ones in angular you can use q. Actually angular uses a subset of q.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the insight. Very nice to know!
2

At the risk of self-promotion, I wrote an NPM module that provides promisified HTTP methods.

2 Comments

This module looks a lot like what Angular $http module is doing. And I can see you are using Bluebird. Nice thanks! I'll take a look.
Good! One difference I just noticed that you'll run into is that where $http returns an error on non-2xx response codes, this will return success. Unfortunately, this isn't highlighted in the documentation.
2

There's an NPM project for running AngularJS in node on the server located here: https://www.npmjs.com/package/angularjs-server

That being said, you might want to take a look at Bluebird or just use ES6 promises in Node. Since Angular is a client-side framework it has a lot of things you don't need on the server.

Comments

1

node has built in support for simple http requests from the http module - however if you would like something a bit simpler and easier to manage I would reccoment the Restify client API

var restify = require('restify');

// Creates a JSON client
var client = restify.createJsonClient({
  url: 'https://us-east-1.api.joyent.com'
});


client.basicAuth('$login', '$password');
client.get('/my/machines', function(err, req, res, obj) {
  assert.ifError(err);

  console.log(JSON.stringify(obj, null, 2));
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.