I have a small website which currently runs on nodejs platform. It uses nodejs for routing and other server side logic and jquery for front end. I would like to bring in Angular 2 for a page in the website which I am yet to build. Is it possible to do that? I am not looking for detailed steps on how to do it, but just wanted to know if its really possible and also worthwhile in doing it? Thanks for your help in advance.
-
You want to replace the whole website or open the angular2 app on a specific route ? Well both cases doable just you have to render index.html of angular2 app on that routeBabar Hussain– Babar Hussain2017-03-15 23:13:26 +00:00Commented Mar 15, 2017 at 23:13
-
Not the whole website. Just that new route that I am planning to develop. Ok I get your point. Just render index.html on that route and the index.html would follow angular2 method of rendering the page. Any input can you provide on the package.json file. As you know, i already have a package.json for my app, should I be creating another one for this particular route or can add angular dependencies to the existing one?SamT– SamT2017-03-15 23:17:05 +00:00Commented Mar 15, 2017 at 23:17
-
You dont need to add angular dependencies in your package.json just build the angular2 app it will generate the dist directory for your production upload whole contents to your server and using express or http server whatever you are using in nodejs create a route and render the index.html which is inside dist thats it and dont forget to change base href of your index.html regarding your routeBabar Hussain– Babar Hussain2017-03-15 23:21:46 +00:00Commented Mar 15, 2017 at 23:21
-
Thanks for helping me out. When I build an angular app, won't it create its own package.json and typings.json files by itself? How I do i separate or integrate with my current nodejs folder structure? I am using express yes. Sorry, my initial question was just a yes or no, but now I am coming with more since its a Yes :)SamT– SamT2017-03-15 23:36:40 +00:00Commented Mar 15, 2017 at 23:36
-
Oh are you saying, keep this new page as a separate Angular2 app in a different folder and call the index.html from the nodejs app folder?SamT– SamT2017-03-15 23:43:05 +00:00Commented Mar 15, 2017 at 23:43
1 Answer
You can definitely do that. The only thing that you will have to do is make sure NodeJS serves the index.html file of your angular 2 SAP. From there everything is based on your front-end architecture and how you want to design the navigation on your SAP.
The only thing that I would be worried about regarding the long-term development is the use of jquery along angular 2. Angular 2 is written in typescript (as far as I know) and you will also bring that along jquery which will add complexity and confusion.
A good development practice is to keep jquery out of AngularJS or Angular 2 instead you could use Angular directives. Of course the learning curve is bigger but you will definitely benefit from it.
How to put together angular2 and nodejs http://thejackalofjavascript.com/developing-a-mean-app-with-angular-2-0/
how to build the main structure of your project https://github.com/angular/angular-cli
automate your project https://scotch.io/tutorials/automate-your-tasks-easily-with-gulp-js
The resource pages are taken from another answer here:
Hope this helps.
EDIT: Keep the routes to your current pages as they are and treat your new page as a single page application for which you might have to build separated api end-point to feed them with resources (user details etc.).