Is nodejs and angularjs are related? - javascript

As nodejs uses npm and angularjs cli also uses npm for modules.
Is there any relation exists between these two?
Installed node.js and tried with hello.js simply single line console.log.
Installed ng module and generated a simple angular app and started server using ng serve -o, kindly help me to clear doubt, if any relation exists between two.

nodeJs is for developing backend, Angular is for developing frontend
You can have a static web site written with Angular and hosting it somewhere like godaddy and that is it
If you need to show some data, interaction with database, submitting data,... then you need a backend, one of the platforms for backend is nodejs, also you can use asp.net webapi, or java or ...

Node and Angular are two distinct entity. In the "web world" there is two distinct things :
Code running on the client side (running in your navigator), frontend, generally using Javascript/HTML/CSS . This code here is used to design your webpage and interact with the user. There is where angular/angularjs work
Code running on server side, backend, this is where people use NodeJS. Here you find more logical code used to manage and to store the data thank to database. Here you can use node express or nestjs to create an http server using node.
Link between both ? Both can communicate using http protocole (we use the angular http client to do that). We simple ask the node server the add/update/remove/calculate data and we play with it :)

Angular.js is a client-side framework that runs in web browsers.
Node.js provides an environment for running JavaScript from a command line.
Angular.js is supported by a bunch of development tools (such as test HTTP servers, and transpilers to convert from TypeScript to ES5). Many of these tools run via Node.js.
You can also use Node.js for server-side programming to support the client-side code in a live environment.

Related

NodeJS and client-side Javascript in Ember application

I am working on developing a client-side application built on EmberJS.
Now, while I test the code in the browser ultimately, I have the following locally for development;
NodeJS & NPM
I have defined bower.json & package.json
I use ember-cli & do ember build & ember server to start the local server
I hit the URL http://localhost:4200 in the browser to access the app
Now my question is I wanted to understand, what exactly is happening here ?
Meaning what exactly happens before code runs in the browser.
I understand when the build happens, it actually pushes code into the 'dist' directory.
Is there any role in NodeJS in all of this (meaning any JS run on server-side in the background) OR we just utilize npm/bower for this case ?
So I just wanted to connect all the dots regarding running in the browser.
browsers don't support the features of modern javascript, so when you end up deploying your ember site, you only need to deploy static files (from the dist directory), and you actually don't need a server at all.
This is how https://emberclear.io works (no server, just a CDN).
The NodeJS things are purely for pre-deployment needs (development, transpiling, testing, etc).
Hope this helps.

How to implement Git in pure Javascript to create a GUI?

after searching quite a lot without findind nothing about it I'm here to ask you if there is a way to implement Git in a pure Javascript web application.
I already know about Git.js but it implements just some basic things and I also wanted to build my own library to learn more in depth about Git.
What I'm not looking for is an API or a lib that could help me.
What I'm looking for is something like:
var command = {{git commit -m "Hello world"}} // Also pure git implementation
gitExecute(command);
I'm still a junior developer and maybe this could be impossible...thanks for the reply :)
What you are asking for may be difficult to do in a browser (because you will need access to the file system to run git commands). What you may need to do is create a NodeJS server which exposes REST endpoints which can be accessed by code in the browser which provides the GUI. The NodeJS server code can run commands as needed and respond to the REST HTTP requests which can be then used by your code in the browser to show/update the GUI.
The disadvantage with this method is that you will need to run your NodeJS server on the computer which has the repository and will not work if the repo is not local to the server.
Another alternative is to use the REST APIs exposed by popular GIT providers like GitHub.
EDIT:
Come to think of it, your usecase may be a good fit for an Electron App. That will allow you to build a desktop app (with access to the filesystem and privileges to execute commands) using Javascript.
For this purpose, NodeJS is mandatory.
You could install git on your server machine, and thene execute your cmds through nodejs' child processes (DOCs)

How to organize Javascript project to allow sharing of code between client SPA and Node server

I am developing an application which comprises a SPA front end and a Rest back-end.
To implement the Rest back-end I am using Node and Express.
Considering that both front-end and back-end are written in JavaScript (and TypeScript), I would like to share some code between these 2 parts (namely Interfaces and simple utils).
So basically my project is composed of three parts: Client, Server, Shared. Therefore I am inclined to have a project directory structure similar to this:
ProjecFolder
ClientFolder
.....
ServerFolder
.....
SharedFolder
.....
I am looking for suggestions on how best organize my project. I have done some research and I have found this interesting article which suggests to use a mechanism based on Gulp tasks that copy all files from SharedFolder into both ClientFolder and ServerFolder and then runs transpling.
I am wondering whether there can be an alternative approach or tools that perform what otherwise has to be configures as Gulp workflow.
My recommendation is to use a package manager tool. When you have dependencies, and the requirements of the server changed, you have to change the module. You don't want the SPA (frontend), to break, when you need to make changes to the server.
This is why package managers give you versions. Each module that depends on your shared code, can use a different version of it. You can use NPM for that. Build a module, publish it, and install it on your frontend and backend.
Many times, in production you split the frontend and backend. The frontend may exist in a file storage system (S3, Google Cloud Storage and similar), and the backend executed on your servers. Then it will be harder to use the same files on both systems.

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?
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.
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
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.

How to run a ReactApp in Apache Tomcat?

I'm able to run any ReactApp only on Nodejs server, but not on a Tomcat server.
Some Qs:
React is purely client side rendered library, and why it requires Nodejs (which is server based)? Why React official Tut recommends Nodejs?
Is it true that Tomcat is for running pure Java applications, and Nodejs for pure JavaScript applications?
I tried to run a sample ReactApplication with few containers in Apache Tomcat, by including the Reactjs include files. But, I get a blank screen. Inspect element shows the non rendered JS source.
Update 1:
If yes for Q1, then Here's a simple React ready application (with all dependencies included) which is easy to run in Nodejs using NPM. How can I run the same app in Tomcat? Can I able to create Web ARchive using this?
1.React is purely client side rendered library, and why it requires Nodejs (which is server based)? Why React official Tut recommends Nodejs?
React is a client-side library but it requires NodeJs for below reasons :
- React uses JSX syntax which browsers doesn't understand and hence it needs to convert into a javascript code that browsers can understand, Babel will do that. Babel needs NodeJs and with the configuration you can convert JSX, ES6 code into ES 5 which browsers can understand
- You may also need node js server if you are using React on server side but this is optional
The sample that you have given needs to transpile into ES 5 code using web-pack which uses Babel. WebPack and Babel both need node js. Hence you need NodeJs.
I don't know what you hide under ReactApp.
But if you use React in client Side you don't need Nodejs server to run it. You can you Nodejs to build it, there is tools to simplify the work. So your ReactApp will be only an HTML page with some js dependencies. Apache or Tomcat can serve it, but for Tomcat you have to bundle it as WAR I think.
But you need rest endpoint to do some stuff, and you can do that with lot of technologies include java and tomcat.
YES

Categories