how to store and delete s3 image using node js


const s3 = new AWS.S3(
{ accessKeyId: IAM_USER_KEY, /* required */# Put your iam user key
secretAccessKey: IAM_USER_SECRET, /* required */ # Put your iam user secret key
Bucket: BUCKET_NAME /* required */ # Put your bucket name
}
);
s3.deleteObject({
Bucket: MY_BUCKET,
Key: 'some/subfolders/nameofthefile1.extension'
},function (err,data){})

www.codegrepper.com
www.stackoverflow.com

how to sort array without using sort method in javascript


function bubbleSort(array) {
var done = false;
while (!done) {
done = true;
for (var i = 1; i < array.length; i += 1) {
if (array[i - 1] > array[i]) {
done = false;
var tmp = array[i - 1];
array[i - 1] = array[i];
array[i] = tmp;
}
}
}

return array;
}

var numbers = [12, 10, 15, 11, 14, 13, 16];
bubbleSort(numbers);
console.log(numbers);

www.codegrepper.com
www.stackoverflow.com

how to send authorization in header of HTTP GET using ajax


var username="username_here";
var password="password_here";
$.ajax({
type: "GET",
url: "myapi.php",
dataType: 'json',
headers: {
"Authorization": "Basic " + btoa(username + ":" + password)
},
success: function (result){
console.log(result)
}
});

AJAX Authorization

www.codegrepper.com
www.stackoverflow.com

how to send emails using nodejs


var nodemailer = require('nodemailer');

var transporter =
nodemailer.createTransport({
  service: 'gmail',
  auth: {
   
user: 'youremail@gmail.com',
   
pass: 'yourpassword'
  }
});

var mailOptions = {
 
from: 'youremail@gmail.com',
 
to: 'myfriend@yahoo.com',
  subject: 'Sending Email using Node.js',
  text:
'That was easy!'
};

transporter.sendMail(mailOptions,
function(error, info){
  if (error) {
    console.log(error);
  } else {

   
console.log('Email sent: ' + info.response);
  }
});

www.codegrepper.com
www.stackoverflow.com

how to send message to specific client using ws node js


var Server = require('ws').Server;
var port = process.env.PORT || 9030;
var ws = new Server({port: port});

var sockets = [];
ws.on('connection', function(w){

var id = w.upgradeReq.headers['sec-websocket-key'];
console.log('New Connection id :: ', id);
w.send(id);
w.on('message', function(msg){
var id = w.upgradeReq.headers['sec-websocket-key'];
var message = JSON.parse(msg);

sockets[message.to].send(message.message);

console.log('Message on :: ', id);
console.log('On message :: ', msg);
});

w.on('close', function() {
var id = w.upgradeReq.headers['sec-websocket-key'];
console.log('Closing :: ', id);
});

sockets[id] = w;
});

www.codegrepper.com
www.stackoverflow.com