concept html in category express

appears as: HTML, HTML, html
Getting MEAN with Mongo, Express, Angular, and Node.js 2ED

This is an excerpt from Manning's book Getting MEAN with Mongo, Express, Angular, and Node.js 2ED.

Back in the early days of the web, people didn’t have high expectations of websites. Not much emphasis was given to presentation; building websites was much more about what was going on behind the scenes. Typically, if you knew something like Perl and could string together a bit of HTML, you were a web developer.

As use of the internet spread, businesses started to take more of an interest in how their online presence portrayed them. In combination with increased browser support for Cascading Style Sheets (CSS) and JavaScript, this interest led to more-complicated front-end implementations. It was no longer a case of being able to string together HTML; you needed to spend time on CSS and JavaScript, making sure that it looked right and worked as expected. And all this needed to work in different browsers, which were much less compliant than they are today.

Figure 2.4. An architecture for delivering HTML directly from the server: an Express and Node.js application at the front, interacting with a REST API built in MongoDB, Express, and Node.js
  • The component AppComponent comprises three files: TypeScript, HTML, and CSS.
  • As you saw earlier in this chapter, with Angular, you can define a class member inside the component code and bind it to the HTML by using curly braces. You could add this to home-list.component.ts to define the name of a location:

    export class HomeListComponent implements OnInit {
      constructor() { }
    
      name = 'Costy';
    
      ngOnInit() { }
    }
    
    
    !@%STYLE%@!
    {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":3,\"ch\":2},{\"line\":3,\"ch\":17}]]"}
    !@%STYLE%@!

    Then you could have this display in the HTML by replacing the location name with the binding, as shown in bold here:

    <a href="/location/590d8dc7a7cb5b8e3f1bfc48">{{name}}</a>
    
    
    !@%STYLE%@!
    {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":45},{\"line\":0,\"ch\":53}]]"}
    !@%STYLE%@!

    The result would be that the browser displays the same way as before, but now part of the data is coming from the code and being bound to the template; it’s no longer hardcoded HTML.

    You’re almost there! You only need to add a tag in the HTML for the application to bind to.

    Express in Action: Writing, building, and testing Node.js applications

    This is an excerpt from Manning's book Express in Action: Writing, building, and testing Node.js applications.

    In figure 1.4, the logging middleware is first in the chain and is always called, so something will always be noted in the log file. Next, the logging middleware continues to the next one in the chain, the authorization middleware. The authorization middleware decides, by some decree, whether the user is authorized to keep going. If they are, the authorization middleware signals that it wants to continue on to the next middleware in the chain. Otherwise, the middleware sends a “you’re not authorized!” message to the user and halts the chain. (This message could be an HTML page or a JSON response or anything else, depending on the application.) The last middleware, if it’s called, will send secret information and not continue to any further middleware in the chain. (Once again, this last middleware can send any kind of response, from HTML to JSON to an image file.)

    In this chapter we’ll talk about views, which give you a convenient way to dynamically generate content (usually HTML). You’ve seen a view engine before; EJS has helped you inject special variables into HTML. But although EJS provided a conceptual understanding of views, we never really explored everything that Express (and the other view engines) had to offer. You’ll learn the many ways to inject values into templates; see the features of EJS, Pug, and other Express-compatible view engines; and explore subtleties in the world of views. Let’s get started.

    EJS can be used for templating HTML, but it can be used for anything. Look at a short bit of EJS in the following listing, and see what that looks like when you render it.

    Listing 7.5. A header EJS file
    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link rel="stylesheet" href="/the.css"> <title><%= appTitle %>/title> </head> <body> <header> <h1><%= appTitle %> </header>