Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run AngularJS2 application without Node server

Is it possible to run an Angular 2 application in browser without using NodeJS as a server. I am not sure, but if i understand correctly the newest browsers are able to compile/"understand" the TypeScript code so i don't have to use any third part js lib to compile it into plain javascript?

I would like to create an application using 100% Angular 2 on frontend and for the backend REST API using Ruby On Rails, without using Rails's page rendering, sessions etc..

I am little confused about it how does Angular2 work/run behind the scenes... How i should configure my Angular2 application to use it without NodeJS?

like image 465
Nagy Ervin Avatar asked Sep 08 '16 19:09

Nagy Ervin


People also ask

Can we run Angular without node?

You do not need to use Node anywhere in production server to use front-end JavaScript frameworks like Angular or react etc. We can use any backend webserver technology written in any language (C# ,Java etc.)

Can we run Angular without server?

You don't need a server-side engine to dynamically compose application pages because Angular does that on the client-side. If the application uses the Angular router, you must configure the server to return the application's host page ( index.html ) when asked for a file that it does not have.

Can we run Angular without npm?

You can run an Angular app on any server that can host static files. There is nothing special about node. So yes, you can use a ruby.

Does Nextjs need node?

You don't need a node server running 24/7 for hosting your application. Also, if you don't use getServerSideProps, Next. js by default will pre-render your page, this page gets cached on a CDN. So yes you can make API calls to your PHP backend, without the need for a setting up a nodejs server yourself.


1 Answers

I think you're mixing up some technologies here.

Server

You can run an Angular app on any server that can host static files. There is nothing special about node. So yes, you can use a ruby. Or an Apache, nginx, lighttpd etc.

The reason for this is that JavaScript is run on the client side. The server's response is only to deliver the JS/HTML/CSS files to the client that is visiting your site.

TypeScript

If you're writing an application with TypeScript you need to transpile it to JavaScript before any browser understands it. You can do this (1) before you're deploying your app to the server or (2) use a library like System.js that will transpile TypeScript on the fly.

While (2) is definitely an option and the Angular CLI used it until recently, (1) is in my opinion the better option. Angular CLI switched to (1) and is now using webpack. Webpack is transpiling and bundling your app before it is hosted on a server.

Hope I could clear things up a bit for you.

like image 81
Sebastian Sebald Avatar answered Oct 01 '22 10:10

Sebastian Sebald