how to set file type and size in multer


var multer = require('multer')
var upload = multer().single('avatar')

app.post('/profile', function (req, res) {
upload(req, res, function (err) {
if (err instanceof multer.MulterError) {
// A Multer error occurred when uploading.
} else if (err) {
// An unknown error occurred when uploading.
}

// Everything went fine.
})
})

www.codegrepper.com
www.stackoverflow.com

how to right plain text format file in node js


var fs = require('fs')
fs.appendFile('log.txt', 'new data', function (err) {
if (err) {
// append failed
} else {
// done
}
})

var fs = require('fs')
var logger = fs.createWriteStream('log.txt', {
flags: 'a' // 'a' means appending (old data will be preserved)
})

logger.write('some data') // append string to your file
logger.write('more data') // again
logger.write('and more') // again

www.codegrepper.com
www.stackoverflow.com

how to rename zip file nodejs


var AdmZip = require('adm-zip');

//create a zip object to hold the new zip files
var newZip = new AdmZip();

// reading archives
var zip = new AdmZip('somePath/download.zip');
var zipEntries = zip.getEntries(); // an array of ZipEntry records

zipEntries.forEach(function(zipEntry) {
var fileName = zipEntry.entryName;
var fileContent = zip.readAsText(fileName)
//Here remove the top level directory
var newFileName = fileName.substring(fileName.indexOf("/") + 1);

newZip.addFile(newFileName, fileContent, '', 0644 << 16);
});

newZip.writeZip('somePath/upload.zip'); //write the new zip

www.codegrepper.com
www.stackoverflow.com

how to read json file in C#


JObject o1 = JObject.Parse(File.ReadAllText(@"c:videogames.json"));

// read JSON directly from a file
using (StreamReader file = File.OpenText(@"c:videogames.json"))
using (JsonTextReader reader = new JsonTextReader(file))
{
JObject o2 = (JObject)JToken.ReadFrom(reader);
}

//For any of the JSON parse, use the website
//http://json2csharp.com/
//(easiest way) to convert your JSON into
//C# class to deserialize your JSON into C# object.

public class FormatClass
{
public string JsonName { get; set; }
public string JsonPass { get; set; }
}
//Then use the JavaScriptSerializer (from System.Web.Script.Serialization),
// in case you don't want any third party DLL like newtonsoft.
public void Read()
{
using (StreamReader Filejosn = new StreamReader("Path.json"))
{
JavaScriptSerializer jss = new JavaScriptSerializer();
var Items = jss.Deserialize<FormatClass>(Filejosn.ReadToEnd());
// Add Code here :)
}
}
//by ahmed ashraf +201111490105

www.codegrepper.com
www.stackoverflow.com

how to read json file in python


import json

with open('data.txt') as json_file:
data = json.load(json_file)

import json

with open('path_to_file/person.json') as f:
data = json.load(f)

print(data)

import json

with open('data.txt') as json_file:
data = json.load(json_file)
for p in data['people']:
print('Name: ' + p['name'])
print('Website: ' + p['website'])
print('From: ' + p['from'])
print('')

reading json file from python

www.codegrepper.com
www.stackoverflow.com