Shyam Hande has Published 72 Articles

Redirecting requests in Node.js

Shyam Hande

Shyam Hande

Updated on 13-May-2020 11:50:28

2K+ Views

Now we have an App.js file shown below, we want to redirect the user back to ‘/’ once user name is received by node server. We will store user name in a file named username.txtInitial App.js file −const http = require('http'); const server = http.createServer((req, res)=>{    const url = ... Read More

Routing requests in Node.js

Shyam Hande

Shyam Hande

Updated on 13-May-2020 11:40:43

1K+ Views

Routing http requests is important because we want to execute different business rules based on request url and the responses will be different for each routes.Earlier we saw, we can get the url by request.url in node. Simple example of user name input with routes is shown below −const http ... Read More

Sending response back from Node.js server to browser

Shyam Hande

Shyam Hande

Updated on 13-May-2020 11:35:41

821 Views

App.js −const http = require('http'); const server = http.createServer((req, res)=>{    console.log(req.url, req.method, req. headers); }); server.listen(3000);As shown in above example code, we have request and response parameter object as an argument in createServer method.Response (res) object will be used to send back data to client. It has many properties, ... Read More

Understanding the http requests in Node

Shyam Hande

Shyam Hande

Updated on 13-May-2020 11:31:28

233 Views

App.jsconst http = require('http'); const server = http.createServer((req, res)=>{    console.log(req); }); server.listen(3000);Run it with command: node App.jsWe can see what is inside a request object by opening a browser and navigating to localhost:3000There is lots of information which will get printed on console window. We will see some important ... Read More

Understanding the Node lifecycle and event loop in node.js

Shyam Hande

Shyam Hande

Updated on 13-May-2020 11:26:49

1K+ Views

Simple http server in node.js will register an event loop which will keep on listening for http requests.Execution of file containing code for creation of server will work as shown below −node App.js => Start executing script => Code parsing, Register events and functions => event loop=> keeps on running ... Read More

Creating a Node.js server

Shyam Hande

Shyam Hande

Updated on 13-May-2020 11:17:53

417 Views

The mostly used core modules of Node.js are −http − used to launch a simple server, send requestshttps − used to launch a ssl secured http serverpath − used to handle path based on operating systemfs − It’s a file system handling moduleos − its used for os related operationsLets ... Read More

JSX in depth in React.js

Shyam Hande

Shyam Hande

Updated on 05-Sep-2019 08:00:25

228 Views

JSX simply creates a React element using createElement method in the end.Example Submit Will be converted to −React.createElement(    FormButton,    {color: 'green', buttonSize: 10},    'Submit’ )Self-closing tags are also possible to add.Capitalizing the custom React ElementThe custom react element must be named with first character in capital so ... Read More

Higher order components in React.js

Shyam Hande

Shyam Hande

Updated on 05-Sep-2019 07:53:53

154 Views

Higher order component in short called as hoc. It’s a pattern which receives a component and returns a new component with add-on features to it.//hoc is the name of a custom JavaScript functionconst AddOnComponent= hoc(SimpleComponent);We use component with state and/or props to build an UI. Similar way a hoc builds ... Read More

Fragment in React.js

Shyam Hande

Shyam Hande

Updated on 05-Sep-2019 07:48:28

389 Views

Most of the times we need to return multiple elements from a component. React Fragment helps in returning multiple elements. The other alternative is to use a html element like div to wrap them. But using extra html node can cause some semantic issues.Example of React.Fragmentrender() {    return ( ... Read More

Forwarding ref in React.js

Shyam Hande

Shyam Hande

Updated on 05-Sep-2019 07:45:54

312 Views

Passing a ref to the child component is called as forwarding ref. React provides a createRef function to create a ref for element.forwardRef is a function to pass the ref to child component.Example// ExampleRef.js const ExampleTextInput = React.forwardRef((props, ref) => (     )); const exampleInputRef = React.createRef(); class NewTextInput ... Read More

Advertisements