30

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?

0

3 Answers 3

37

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.

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

4 Comments

Thank you very much for your answer :)
Hi @SebastianSebald , thanks for the answer. But I have a doubt. I made the tutorial of tour of heroes of angular 2 website and when I've finished, It works perfectly locally running npm start, but if I put it on a server (with apache), it doesn't load. Do you know what could happen? Thanks!
Not without any Stack trace. But this is not the place to discuss your issue. Please create a new question. Surely you get some help. On a side note: npm start may also transpile your files. Make sure you're using the JS output, not the TS.
AoT, or ahead of time compilation, would be worth looking into for anyone looking into this
16

TL;DR

If you use TypeScript with Angular 2, you only need Node during development:

DEV: NodeJS is used to transpile .ts files to .js files.

PROD: Generated .js files are used inside the browser, NodeJS is not required anymore, except if you also happen use it in the backend.

NOTE: If you only use plain JS in development you do not even need Node

Comments

2

You can use any server side technology including Asp.Net Core, Node.Js, PHP to server the js, html and css content.

While building the application in the IDE, the Node.js transpile the .ts files into .js file.

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.