2

I've task: X company has created Z school, in school there is only one class. School needs: 1. to create students' list:

a. id
b. name
c. surname
d. birth date
e. addresses
f. scores

How can I post request in node.js to get all these above information? I'm using Firebase and get request is already done. maybe I'm asking question wrongly, cause I'm an amateur and sorry for that.

This is my code:

const express = require('express');
const { admin } = require('../firebase');
const app = express();

app.get('/', (req, res) => {
    const reference = admin.database().ref('/students')

    reference.on('value', (snapshot) => {
        res.json(snapshot.val())
        reference.off('value')
    }, (errorObject) => {
        res.send(`somethig wrong: ${errorObject.code}`)
    })
})

app.post('/', (req, res) => {

})

module.exports = app
2
  • 1
    You haven’t tried anything in the post yet Commented Feb 15, 2020 at 12:26
  • I know, and I'm asking how can I do it Commented Feb 15, 2020 at 12:29

1 Answer 1

1

You could use axios to send POST requests through your web application like the following example:

axios.post( '/student', { name: 'John', sname: 'Cage' })
     .then( function( resp ) {
       console.log( resp )
     })
     .catch( function( err ) {
       console.error( err )
     })

Now you can listen "/student" (the POST request) from your NodeJS server:

app.post( '/student', (req, res) => {
  // Your new student data
  console.log( 'Name:', req.body.name )
  console.log( 'Surname:', req.body.sname )
})
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.