0

Hi I have a node based server api, and have created a simple web app using angular 2.But I don't understand how to integrate both. I have done a little research but most of the websites are only offering how to built angular 2 application and no one offers node integration.

6
  • You probably want to expose some REST API on your node application and use Angulars Http service from HttpModule to make calls to the REST API of your server. Commented Dec 11, 2016 at 14:36
  • I don't understand do i run node or npm start angular. Will there be 2 package json files ? @GünterZöchbauer Commented Dec 11, 2016 at 14:38
  • Do you need sample code? Commented Dec 11, 2016 at 15:07
  • @HassanFalahi It would be really nice to have a sample, could use one Commented Dec 11, 2016 at 15:11
  • look at bellow link. Commented Dec 11, 2016 at 15:30

2 Answers 2

2

Notice that Nodejs is simple server-side Javascript, so you have to follow one of these approches:

  1. Server side web app: In this case all pages (and functionality) will render in server-side. You can find lots of framework for doing that. So you need no client-side framework like angularjs.

  2. Client side web app + server side api: I think that is something you need. Server side api has build as rest api service and serves all your business functionality. In client-side angular just consumes these services. All client based functionally will handle with angularjs (like routing, async service call, manages states and etc)

Or if your question is how comminucate with node-js rest api look at this page: angular2 http

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

Comments

0

You can install any web server for angular like apache or nginx. For example u're using apache, when you run apache you can access angular web through http://localhost/project.

Follow this tutorial on how to install and run nodejs http://blog.modulus.io/absolute-beginners-guide-to-nodejs on window. On mac https://shapeshed.com/setting-up-nodejs-and-npm-on-mac-osx/

You can call node server using REST API.

In your angular service for example :

$http.get('http://project/rest/getData', succFn).then(function (res) {
                            return succFn(res.data);
                        }, 'error');

In nodejs (REST Server) :

apiRoutes.get('/getData', function (req, res) {
      // Return any data to client
      res.json({
        'code': '00',
        'content': 'Return dummy or json here',
        'remarks': 'Success'
  });
}

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.