Is there a way to know the template engine of a web site? - node.js

I'm retro engineering a couple of web apps to figure out which technologies are behind them so I can know which one I can use or learn to build my own web app
So, going through the app I can see that it's based on NodeJs and ExpressJS and luckily I know both of them.
But what I can't figure out is the template engine, there's a lot of template engines that are really friendly to Express(Jade, EJS, HandleBars, etc...)
So I was wondering if there is a way to know which template engine is used on a web site

Not normally. The whole point of a template engine is to replace special characters with user facing content so that precludes the type of hints one would need to determine the template engine. One would need to see the server side source code to really know.

Related

What is templating/template engine

I did a course on full-stack on web and afterwards I applied for internship.
In the internship the interviewer asked me a question related to templating engine in NodeJS and the terms sounded totally alien to me.
So I came home and was only able to figure out npm modules like moustache..
So can someone explain me what is templating/template engine in NodeJS.
Templating Engines are to split code for example you got a web application you can split the footer, header, body, layout and more to use it on other pages.
You can also use the templating engines to connect them to your modules and functions for example:
You can have a button in ejs or pug and if you click it you can run an acction from your app.js. I personally use templating engines with combination of frameworks like express.js.
In the next interview you can say:
Templating engines in nodejs can be used to split the nodejs application code from the frontend layout and the frontend elements can be used dynamically with the node application for example if you click a button it can run a action from your node app.js. This can be used for any type of application and it can have user input interactions like a form field that the user can fill up and that the input gets saved to a database like MongoDB. With the templating engine, you can have the frontend interact with the nodejs application.
Templating engines are also used to split elements into multiple components like:
footer, header, head, layout and more. So you don't need to rewrite those elements for other pages and that way your application can scale easily.
Templating engines are mostly used in combination with nodejs frameworks like express.js for example.
I can also recommend you this tutorial it's a good explanation of templating in nodejs using ejs and express.js. They are way more templating engines but ejs is widely used and very popular so I would recommend learning this first.
In Nodejs the most used templating engines are pug and ejs
Please let me know if you got question and I really hope I could help you.
greetings,
Karim
Simply said 'Templating' engine is an engine that can manipulate your HTML code from the server side using the server side code you use. By it's very authentic built in syntaxes you can loop, change content dynamically, alert messages to user and etc.
there are tons of templating engines out there
Laravel - blade templating engine
ASP.NET - Razor blade templating engine
Node.js - handlebars, Pug and few others

How to deploy TerriaJS on my site

I would like to deploy an instance of TerriaJS on my site for the purpose of 3D (with 2D-fallback) geospatial mapping. I am a bit confused as to how to actually "deploy" TerriaJS on my site. I am very familiar with Leaflet... pretty much just include the leaflet.js file, create a div, and off you go. However, I am running through the wiki on TerriaJS's github page and all I see is a bunch of NodeJS.
What am I missing? I am able to get the map to run with NPM and I see a nice 3D map (running inside of a node web server instance), but that doesn't do me any good as I want to be able to embed the map on my web site.
If anyone has a nice (plain English) tutorial or starting point, that would be awesome.
Thanks.
The Node-based web server that we usually use with TerriaJS only does a few things:
It serves up the static HTML, JavaScript, and CSS that make up the application.
It includes a simple service at /proxy that allows TerriaJS to access geospatial data servers that don't support CORS.
It includes another service at /convert that uses OGR to transform geospatial vector data (e.g. shapefiles) to GeoJSON for display by the TerriaJS client.
Of these, only the first is required. So, you can copy the wwwroot directory of a working TerriaJS application up to whatever web server runs your site and it will run there just as well as it does on the Node-based server. You'll have to make sure that all of your geospatial data is either on the same server or is hosted on servers that support CORS, and shapefile conversion won't be supported, but other than that you should be good to go.
Embedding TerriaJS in an existing web page is a bit trickier. You'll want to start with the index.js, index.html, and index.less files in the TerriaJS app you started with (NationalMap maybe?) and modify them to suite your needs. You'll need to use the gulp-based build process. But once that is all done, you can just copy the files up to your web server as before.
Depending on your needs, you may also consider embedding TerriaJS on your page in an iframe rather than building it into the page directly. You can control the content of the catalog and customize some basic aspects of the UI by specifying parameters to the URL. You can also control it by posting cross-window messages as described here.
Finally, it's possible to use TerriaJS without the provided user interface, e.g. by providing your own. This is a pretty advanced scenario, though, so probably best to post a separate question if you want to go down that road.

Are NodeJs applications crawlable by search engines?

If I use Jades template engine with NodeJs will the app be crawlable by search engines and Facebook without using the _escaped_fragment_?
If your application outputs HTML, it is no different than if you had written that HTML in a file and simply served the file. The wider Web doesn't generally know or care what you're using to generate your HTML.
(It is possible to infer what tech a page is using by inspecting headers and looking for common idioms that are unique to a particular technology, but these are just clues, not a fundamental difference in what your Web page is.)

Actual use of Jade template and angularjs

I am building a website using nodejs and express. How to make divisions in a page dynamic? Is Jade used for that? if not how to do it?what is angularjs used for? Please help i searched a lot on google and i couldn't get a clarity in the usage of them.
Jade creates the html used in the browser on the server-side. The browser executes a request to the web-server, the web-server executes Jade, which will generate the html that will be sent to the browser. This server-side content generation has been very common in the last ~20 years, but it has quite some cons when building rich internet application. Mostly this has to do with performance and client state tracking.
AngularJS is a client-side MVC/MVVM like framework to build so called Single Page Applications (SPA), which allows you to have the complete user interface flow, all content generation and state tracking to be done at the client side. It even allows you to build offline applications. From the developer point of view this feels much more like building a desktop application where the client knows the state of the user interface. From the user point of the view the website will respond much smoother and snappier because the UI is all generated locally.
Note: SPA does not mean that you can only have one page in your website.
It's a technical term where the browser downloads one page (~/index.html), which contains the complete or partial web application. The user technically never leaves this page, but the content (pages) is dynamically swapped in and out from this placeholder page.
To most common way to provide data to a SPA is via RESTful web services. AngularJS comes with builtin support for REST.
Some developers combine server-side content generation techniques with AngularJS, but there's actually no real need for this.
Jade is used as a template engine on both server-side and client-side. Yes, it can update a page dynamically, you just have to compile your jade templates to a javascript functions (using jade -c or something similar).
Yes, you can use angular.js with it, but I see no real need to use two template engines in your project. Suggesting to just stick with jade, unless you know what are you doing.

AngularJS with Express Templates or pure HTML? Pros and Cons?

Express JS uses templates for generating HTML and then server sends them to client in response. There may be several other templates from which HTML can be generated. The ones I was able to discover are:
Jade (http://jade-lang.com/)
EJS (http://embeddedjs.com/)
In my app, I need to use both ExpressJS and AngularJs. I am new to both technologies. While learning angular, I had to use it in pure HTML. After learning ExpressJs, I realized, in order to use angularjs, I need to use them in any of the above templates which will be converted to HTML while sending to client.
Now, I want to use expressjs as my server and angularjs as my client side app. For this, I think I have two options.
Option 1
I can stop using templates altogether and use our NodeJS server to respond by sending simple HTML files. These HTML files will then contain AngularJS coding within them. AngularJS then, on client side, will act as our application. It will demand other HTML documents from the server. Or it can also be used like AJAX, where we can only request the piece of information to update just part of the page rather refreshing the whole page for a minor change.
Option 2
I can use angularjs inside expressjs templates (jade or ejs).
Kindly, help me in understanding the pros and cons of both options. Which one will be your choice in such case.
This is very much an opinion question and Stack Overflow admins hate anything that smacks of opinion, but here's my experience and opinion nevertheless.
I've done a couple of apps now using purely static files (HTML, CSS, and JavaScript) with those calling a service on the back-end to deliver the data. It reduces the back-end, whatever it is (I've used both Java and Node.js), to just being a set of service URLs but it works very very well.
You've got a fantastic hard line between the responsibilities of the
two systems
It's very easy to work on and test each one independently
Bugs are usually very clearly in the front-end or the back-end (all
you have to do is look at the data transferred to know)
The back-end services are ready to be reused to support alternative UIs from the
command line or something mobile specific if you want
You can use one technology for the back-end to start with (say Node.js or Ruby on Rails) and then switch to something else later if you need to. As long as the API stays the same the front-end never knows.
I personally use AngularJS with Express/Jade. The setup is actually pretty simple and I find writing Jade much more enjoyable than writing HTML. I've also adopted writing my Angular code in CoffeeScript as, again, it makes for quicker development. If you are looking to save keystrokes then Jade is a great solution and its integration with Express makes it a no brainer. If you aren't worried about producing code more quickly then there is absolutely no problem with using HTML.
I will point out that one of the greatest benefits I have found to using Jade over HTML is the ability to develop a single page in multiple files, then use include to have them concated before compiling into HTML. This allows you to take larger pages and break them into more manageable chunks. Together with Angular's templating, this can relieve much frustration.
Really it is all a matter of opinion, but since I decided to give Jade a shot, I have not regretted it and I have never ran into a situation where my HTML was rendered incorrectly when using Angular.
I went with option 1 because I didn't want to deal with any potential issues with jade or ejs converting the template incorrectly and interfering with Angular. My app essentially has the index page (which is really just the basic page template with my css and js includes) come out of Express as jade and then angular takes it come there and all my angular templates are in a separate location than my jade template.

Resources