There's more...

In our /routes/angular.js route configuration, we will use the path and fs core libraries of Node.js, as follows:

fs.readFileSync(
path.join(angularBuildPath, 'index.html'),
{encoding: "utf8"}
)

The fs module is Node.js's file system library that allows us to read and write from the operating system's file system. Here, we are using it to synchronously read the index.html file from our Angular project. We could have just as easily used the asynchronous version of the fs.readFile method; however, seeing as it is a one-time operation on server startup, the simplicity of just making this call synchronous works fine.

The path module is Node.js's core library for working with file system paths. Windows and Unix operating systems suffer from incompatible file path standards, so this library deals with normalizing operations for consistently building file paths. When you are writing paths to load files, you should always use the path library so that your file paths will work on all node-compatible environments.

You can learn more about the fs and path modules and their capabilities in the official Node.js documentations:

https://nodejs.org/api/fs.html
https://nodejs.org/api/path.html

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.157.151