Posts

How to add 404 page in angular routing ?

Image
  How to add 404 page in angular routing ? To add a 404 page in the angular routing, we have to first create a component to display whenever a 404 error occurred. In the following example, we will create a angular component called  PagenotfoundComponent . To create angular component use below command ng generate component pagenotfound   Once component is created add below code in it. <div> <h1>404 Error</h1> <h1>Page Not Found</h1> </div> Then inside the routing file, we have to provide this component route and make this available for every 404 requests. So, inside the  app-routing.module.ts  file, we have to create a new route for this PagenotfoundComponent. import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { PagenotfoundComponent } from './pagenotfound/pagenotfound.component'; import { PostCreateComponent } from './posts/post-create/post-create.component'...

Express - Production Best Practices: Security

Image
Security best practices for Express applications in production include:   Don’t use deprecated or vulnerable versions of Express Use TLS Use Helmet Use cookies securely Prevent brute-force attacks against authorization Ensure your dependencies are secure Avoid other known vulnerabilities Additional considerations Don’t use deprecated or vulnerable versions of Express Deprecated or outdated versions of Express 2.x and 3.x are no longer maintained. Security and performance issues won’t be fixed. Do not use them! If you haven’t moved to version 4.If you are, update to one of the stable releases, preferably the latest. As a developer, you absolutely migrate to Express 4. This version is a revolution! It is quite different in terms of the all aspects. Use TLS If your app deals with or transmits sensitive data, use  Transport Layer Security  (TLS) to secure the connection and the data. This technology encrypts data before it is sent from the client to the server, thus preventin...

How to use NgClass in angular?

Image
NgClass      The NgClass directive allows you to set the CSS class dynamically for a DOM element.      There are two ways to use this directive, the first is by passing an object literal to the                directive.            You can use NgClass using below syntax                               [ngClass]="{'text-success':true}"        When using an object literal, the keys are the classes which are added to the element if the value of the key evaluates to true. So in the above example, since the value is true this will set the class text-success onto the element the directive is attached to. The value can also be an  expression , so we can  re-write  the above to be. [ngCl...

While reloading the page I got 404 error for angular.

Image
       I am using  angular  application; I have no problem in running on localhost when I hosted my application on server. When I clicked the employee button it loads the employee details. However I refreshed the same page, It gives me  404 file  or directory not found error.                     I have fixed the issue using routing strategies(HashLocationStrategy) approach. This will make the links look like   http://domain.com/#/page  for the url   http://domain.com/page . In  app.module.ts , we need to import   HashLocationStrategy, LocationStrategy .  And then in NgModule Provider add   {{provide: LocationStrategy, useClass: HashLocationStrategy}} . App.Module.Ts import { BrowserModule } from  '@angular/platform-browser' ; import { NgModule } from  '@angular/core' ; import { HashLocationStrategy, LocationStrategy } from  '@angular/...