Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

node http post

const https = require('https');

const data = JSON.stringify({
    name: 'John Doe',
    job: 'Content Writer'
});

const options = {
    hostname: 'reqres.in',
    path: '/api/users',
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Content-Length': data.length
    }
};


const req = https.request(options, (res) => {
    let data = '';

    console.log('Status Code:', res.statusCode);

    res.on('data', (chunk) => {
        data += chunk;
    });

    res.on('end', () => {
        console.log('Body: ', JSON.parse(data));
    });

}).on("error", (err) => {
    console.log("Error: ", err.message);
});

req.write(data);
req.end();
Comment

node send post request

const axios = require('axios')

axios
  .post('https://whatever.com/todos', {
    todo: 'Buy the milk'
  })
  .then(res => {
    console.log(`statusCode: ${res.statusCode}`)
    console.log(res)
  })
  .catch(error => {
    console.error(error)
  })
Comment

node js post method

fetch('',{
	method:'POST',
  	headers:{
    	'content-type': 'application/json'
    },
  	body:JSON.stringify(users)
})
.then(res=> res.json())
.then(data => console.log(data))
Comment

nodejs request post

const axios = require('axios');

axios.get('https://jsonplaceholder.typicode.com/users')
  .then(res => {
    const headerDate = res.headers && res.headers.date ? res.headers.date : 'no response date';
    console.log('Status Code:', res.status);
    console.log('Date in Response header:', headerDate);

    const users = res.data;

    for(user of users) {
      console.log(`Got user with id: ${user.id}, name: ${user.name}`);
    }
  })
  .catch(err => {
    console.log('Error: ', err.message);
  });
Comment

post nodejs

app.post(url,function(res,response){
  res.sendFile(~);
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to make javascript function consise 
Javascript :: filter function using recursion 
Javascript :: nodejs send download file from buffer 
Javascript :: TypeError: path must be absolute or specify root to res.sendFile 
Javascript :: how to pass callback function in javascript 
Javascript :: js download 
Javascript :: call a function 
Javascript :: onomonrieah 
Javascript :: addAndRemoveClassJquery 
Javascript :: hincrby nodejs 
Javascript :: create 2d array in javascript filled with 0 
Javascript :: how to sepaarte text in object javascript 
Javascript :: change text based on dropdown selection javascript 
Javascript :: google translate javascript 
Javascript :: how to assign onEdit to specigfic tab 
Javascript :: jsx not working in react vscode 
Javascript :: JavaScript Code to Perform GCD using Recursion 
Javascript :: what is package.json in node 
Javascript :: JavaScript try...catch Statement 
Javascript :: js how to get element csswidth 
Javascript :: Expo camera rotation 
Javascript :: load jquery in console 
Javascript :: convert string to regular expression js 
Javascript :: write data in props.histroy.push in react component 
Javascript :: cloudflare worker read url params 
Javascript :: http status code 406 
Javascript :: Recorrer Array con forEach 
Javascript :: js startswitch 
Javascript :: How to get maximum value in Javascript 
Javascript :: how to migrate data from one elasticsearch to another 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =