├── blocking or non-blocking.js ├── first node.js ├── fs module.js ├── osmodule.js ├── package-lock.json ├── package.json ├── path module.js ├── rohan.txt ├── second.js ├── serving html by backend.js ├── tut61.html └── tut63.js /blocking or non-blocking.js: -------------------------------------------------------------------------------- 1 | // Synchronous or blocking 2 | //line by line execution 3 | 4 | /*Asymchronous or non-blocking 5 | line by line exexution not guaranteed 6 | callback will fire */ 7 | 8 | 9 | const fs = require("fs"); 10 | fs.readFile("dele.txt", "utf-8", (err,data)=>{ 11 | console.log(err,data) 12 | }); 13 | console.log("This is the message") -------------------------------------------------------------------------------- /first node.js: -------------------------------------------------------------------------------- 1 | const harry = require("./second"); 2 | 3 | console.log("hello world", harry) 4 | -------------------------------------------------------------------------------- /fs module.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | let text = fs.readFileSync("dele.txt", "utf-8"); 3 | text = text.replace("brower","program") 4 | 5 | console.log("The content is") 6 | console.log(text); 7 | 8 | console.log("creating a new file") 9 | fs.writeFileSync("rohan.txt", text) -------------------------------------------------------------------------------- /osmodule.js: -------------------------------------------------------------------------------- 1 | const os = require('os'); 2 | 3 | console.log(os.freemem()) 4 | console.log(os.homedir()) 5 | console.log(os.hostname()) 6 | console.log(os.platform()) 7 | console.log(os.type()) -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fardin", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fardin", 3 | "version": "1.0.0", 4 | "description": "its an amazing package", 5 | "main": "first node.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "fardin", 10 | "license": "ISC", 11 | "dependencies": {}, 12 | "devDependencies": {} 13 | } 14 | -------------------------------------------------------------------------------- /path module.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | 4 | const a = path.basename('C:\\temp\\myfile.html'); 5 | const a2 = path.dirname('C:\\temp\\myfile.html'); 6 | console.log(a) 7 | console.log(a2) 8 | 9 | const a3 = path.extname(__filename) 10 | console.log(__filename,a3) -------------------------------------------------------------------------------- /rohan.txt: -------------------------------------------------------------------------------- 1 | Hello I am Adam Warlock or Starlord or warlord 2 | and I am the student of Ra's Ghul -------------------------------------------------------------------------------- /second.js: -------------------------------------------------------------------------------- 1 | // (function(exports,require,nodule,_filename,_dirname){ 2 | 3 | harry = { 4 | name:"harry", 5 | favNum:3, 6 | developer: true 7 | } 8 | console.log(exports,require,nodule,_filename,_dirname) 9 | module.export = harry; 10 | // }) -------------------------------------------------------------------------------- /serving html by backend.js: -------------------------------------------------------------------------------- 1 | const http = require('http') 2 | const fs = require('fs') 3 | const fileContent = fs.readFileSync('tut61.html') 4 | 5 | const server = http.createServer((req, res)=>{ 6 | 7 | res.writeHead(200, {'content-type':'text/html'}) 8 | res.end(fileContent) 9 | }) 10 | server.listen(80, '127.0.0.1', ()=>{ 11 | console.log("Listening on port 80") 12 | }) -------------------------------------------------------------------------------- /tut61.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, reprehenderit. Quam culpa eius aliquam id cumque saepe, provident odio sed eos quia nihil modi error voluptate vero autem quibusdam aperiam exercitationem! Quam, consequuntur velit.
62 | Read more 63 | 64 |