Skip to content

Instantly share code, notes, and snippets.

View sreepurnajasti's full-sized avatar

sreepurna sreepurnajasti

View GitHub Profile
@sreepurnajasti
sreepurnajasti / readSheet.js
Created August 28, 2018 05:26
Reading xlsx, csv files using exceljs in node
var Excel = require('exceljs');
var workbook = new Excel.Workbook();
workbook.xlsx.readFile('../../storage/cust_88ae31d4-47c5-4f70-980e-7b473ba20ef9/xls.xls')
.then(function() {
var worksheet = workbook.getWorksheet('Sheet1');
worksheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
console.log("Row " + rowNumber + " = " + JSON.stringify(row.values));
});
});
For setting proxy:
npm config set strict-ssl false
npm config set registry http://registry.npmjs.org/
npm config set https-proxy http://un:pw@proxyadd:port/
npm config set proxy http://un:pw@proxyadd:port/
For removing proxy:
npm config rm proxy
@sreepurnajasti
sreepurnajasti / index.js
Created June 29, 2018 08:03
Using request module with proxy
var request = require('request');
var r = request.defaults({'proxy':'http://192.168.1.1:3128'});
r('http://www.google.com', function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
});
@sreepurnajasti
sreepurnajasti / asyncAwait.js
Created June 28, 2018 08:53
use of async await functionality
function resolveAfter2Seconds(x) {
return new Promise(resolve => {
//resolve(x)
});
}
async function f1() {
var x = await resolveAfter2Seconds(10);
console.log(x); // 10
}
@sreepurnajasti
sreepurnajasti / main.html
Last active June 27, 2018 09:18
multiple file upload using nodejs, jquery ajax(xhr) in frontend
<html>
<head>
<title>File upload Node.</title>
</head>
<body>
<form id="uploadForm" enctype="multipart/form-data" action="/api/photo" method="post">
<input type="file" name="userPhoto" multiple accept=".xlsx,.xlx,.csv"/>
<input type="submit" value="Upload Image" name="submit">
<!-- <input type='text' id='random' name='random'><br> -->
<span id = "status"></span>
@sreepurnajasti
sreepurnajasti / server.js
Created June 21, 2018 12:35
Nodejs mysql operations
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mysql = require('mysql');
var con = mysql.createConnection({
host:"localhost",
user:"root",
passsword:"sree",
database:"emp"
});
@sreepurnajasti
sreepurnajasti / main.html
Last active January 27, 2023 00:51
send form data from html form using jquery ajax(serialize method) to express Nodejs
<!doctype html>
<html>
<head>
<title>AJAX/Express Example</title>
</head>
<body>
<form id="signup" method="POST" action="/addUser">
<div>
<label for="name">Name</label>
<input name="name"type="text" id="name" />
@sreepurnajasti
sreepurnajasti / main.html
Created June 19, 2018 08:27
upload single file from client( jquery, ajax) to server(express, multer)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Upload File</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
@sreepurnajasti
sreepurnajasti / index.html
Last active June 18, 2018 09:20
upload single file from client to server
<!DOCTYPE html>
<html lang="en">
<head>
<title>Simple Multer Upload Example</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<form action="/" enctype="multipart/form-data" method="post">
<input type="file" name="file-to-upload">
@sreepurnajasti
sreepurnajasti / cluster.js
Last active June 12, 2018 06:51
simple cluster application
var cluster = require('cluster');
var count = 0;
function *sendRequest(){
for (var i=0; i<10000; i++) {
count++;
yield i;
if(count == 10){
process.exit(0);
}
}