-2

I recently got into website development and am in the process of making my first website using Angular 2 right now. I already created websites in the past using basic HTML and PHP but that was nothing special and the quality of code was pretty low. "Back in the days" I just created different files for different tasks, e.g. login, creating a comment and so on. Nowaydays this kind of practices seems kinda clumsy.

Now, I read about REST APIs and from my understanding this is what I am going to need to have a clean way to let my frontend communicate with my backend. Basically from my understanding I am going to have an application which purpose is to communicate with my database as soon as my frontend sends a request to it - Right? So what I am going to do is to create an API which fits my needs. Is it possible to have my frontend and my backend-database-API-thing on one server?

Moreover, I got into NodeJS because NodeJS seems exactly like what I need here. However, is it correct that I need a special server which actually supports to let me run NodeJS applications? If yes, what are my alternatives? I don't want to switch providers right now. I saw that it is possible to create an REST API using PHP - Is that common? Is that "good practice"? Or is that some old ass workaround which should not be used anymore?

I am grateful for any kind of input. I feel kinda lost right now with what to pick up for which task.

  • 1
    1) REST is a way to expose a service to the world. You don't have to use this architecture style, although it is a popular one. 2) One server can serve your webapp and your API, but it is important to understand that your Angular application will actually be executed on your visitor's computer. 3) It's not exactly clear what you mean by special server. Of course, if you write your backend in Node.js it has to have all the dependencies required to run it. Node.js is one possiblity among others. You can write your backend in any language, including PHP if that's what you want. – Vincent Savard Nov 8 '16 at 19:54
0

Overall, a "Single-Page Application" (which is what you're describing) has an architecture that looks something like this:

Database <--SQL--> DAL <--CRUD--> Service Layer <--REST--> Angular 2 in User's Browser
|---------------- BACKEND --------------------|| Internet ||------- FRONTEND --------| 

The DAL communicates with the database using SQL or whatever API the database provides. The Service Layer translates your business transactions from REST calls to CRUD operations. Your Angular 2 app (which runs in the user's browser) will implement your business processes by communicating with your Service Layer using REST calls.

There are several technologies that you can use for the layers that create the REST API. Regardless of which technology you choose, the REST API isn't going to change.

You'll have to ask your provider what they support.

0

Yes, the idea of the "backend" is that special machine(s) do the database manipulation and other heavy lifting, and frontend code that runs in the browser talks to it via an API.

You don't need any special setup to run Node.js, except what is described in Node.js setup guides; node is just a regular program. If your provider gives you a virtual server, you're likely all set. If you run on a shared hosting with a provider-managed PHP installation, then yes, this is not going to be sufficient. Maybe your provider offers hosted Node, too?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.