Email - harun.bspt2014@gmail.com Phone - +8801717615827

HTTP-Status-Codes-Understanding-Express-res.status

The res object represents the HTTP response that an Express app sends when it gets an HTTP request.

Source: https://www.tutorialspoint.com/nodejs/nodejs_response_object.htm

res.status(code) res.status(code)

This method is used to set the HTTP status for the response. Following are a few examples

So, below are examples when I am setting the response codes

res.status(403).end(); res.status(400).send(‘Bad Request’); res.status(404).sendFile(‘/absolute/path/to/404.png’);

So, below are examples when I am first getting the response codes from the express server and based on that I am logging out my current user

https://github.com/rohan-paul/SignUp-Form-with-Passport/blob/master/src/components/navbar.js

logout(event) {
        event.preventDefault()
        console.log('logging out')
        axios.post('/user/logout').then(response => {
          console.log(response.data)
          if (response.status === 200) {
            this.props.updateUser({
              loggedIn: false,
              username: null
            })
          }
        }).catch(error => {
            console.log('Logout error')
        })
      }

Some other Response Object Methods

res.append(field [, value])

This method appends the specified value to the HTTP response header field. Following are a few examples

res.cookie(name, value [, options])

This method is used to set cookie name to value. The value parameter may be a string or object converted to JSON. Following are a few examples −

Dr. Harun
Dr. Harun

Dr. Md. Harun Ar Rashid, MPH, MD, PhD, is a highly respected medical specialist celebrated for his exceptional clinical expertise and unwavering commitment to patient care. With advanced qualifications including MPH, MD, and PhD, he integrates cutting-edge research with a compassionate approach to medicine, ensuring that every patient receives personalized and effective treatment. His extensive training and hands-on experience enable him to diagnose complex conditions accurately and develop innovative treatment strategies tailored to individual needs. In addition to his clinical practice, Dr. Harun Ar Rashid is dedicated to medical education and research, writing and inventory creative thinking, innovative idea, critical care managementing make in his community to outreach, often participating in initiatives that promote health awareness and advance medical knowledge. His career is a testament to the high standards represented by his credentials, and he continues to contribute significantly to his field, driving improvements in both patient outcomes and healthcare practices.

Translate »
Register New Account