Events createReadStream() in node js

var fs = require('fs'); var readStream = fs.createReadStream('./myrenamedfile.txt'); /*Write to the console when the file is opened:*/ readStream.on('open', function () { console.log('The file is open'); }); if file myrenamedfile.txt exists…

0 Comments

URL Cutting in node js

A. In index.js var url = require('url'); var adr = 'http://localhost:8080/default.htm?year=2017&month=february'; //Parse the address: var q = url.parse(adr, true); /*The parse method returns an object containing url properties*/ console.log(q.host); console.log(q.pathname);…

0 Comments

Rename file in node js

var fs = require('fs'); fs.rename('mynewfile3.txt', 'myrenamedfile.txt', function (err) { if (err) throw err; console.log('File Renamed!'); }); After save this file 'mynewfile3.txt' to 'myrenamedfile.txt'.

0 Comments

Delete file in node js

var fs = require('fs'); fs.unlink('mynewfile1.txt', function (err) { if (err) throw err; console.log('File deleted!'); }); It will delete this file 'mynewfile1.txt' after save this code.

0 Comments

Write file in node js

var fs = require('fs'); //Replace the file with a new one: fs.writeFile('mynewfile3.txt', 'This is my text.', function (err) { if (err) throw err; console.log('Replaced!'); }); // You can write anything…

0 Comments

Create files in node js

var fs = require('fs'); //create a file named mynewfile1.txt: fs.appendFile('mynewfile1.txt', 'Hello content!', function (err) { if (err) throw err; console.log('Saved!'); }); After refress this file it is creating new file…

0 Comments

File system in node js ( Read file )

A. Create new file suppose read.html <form> <input type="text" name="" placeholder="Enter your name.."> </form>   B. In index.js var http = require('http'); var fs = require('fs'); http.createServer(function (req, res) {…

0 Comments