Node.js is a compatible runtime scenario for compiling JavaScript code outside of a browser. It was created on Chrome’s Javascript Engine. The Express.js functions between request and response cycles. It’s a Middleware framework for managing the routing of different web pages. A Middleware can request:
app.get(path, (req, res, next) => {}, (req, res) => {})
(req, res, next) => {}
: The Middleware function. It defines actions to be done before the webpage can be viewed and other functions can be called.
Make sure that Node.js is installed on your computer. To create a Node.js project, we need to create a file named app.js
.
The following code shows the creation of Middleware.
import React from 'react'; require('./style.css'); import ReactDOM from 'react-dom'; import App from './app.js'; ReactDOM.render( <App />, document.getElementById('root') );
const
values, which specify when to use Express.js.app.get
request fires a route handler. In this case, the handler fires on the "/"
keyword, and it directs to a page where two lines between the braces are printed.