Skip to content

Instantly share code, notes, and snippets.

@bablukpik
Last active April 26, 2017 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bablukpik/3762fad8d76cbb742556ef415ad4e6e6 to your computer and use it in GitHub Desktop.
Save bablukpik/3762fad8d76cbb742556ef415ad4e6e6 to your computer and use it in GitHub Desktop.
Runtime vs Compile time:
-> In computer programming, event-driven programming is a programming paradigm in which the flow of the program is determined by events such as user actions (mouse clicks, key presses), sensor outputs, or messages from other programs/threads.
-> The source code must be compiled into machine code in order to become and executable program. This compilation process is referred to as compile time.(think of a compiler as a translator) A compiled program can be opened and run by a user. When an application is running, it is called runtime
-> In computer science, asynchronous I/O, or "Non-sequential I/O" is a form of input/output processing that permits other processing to continue before the transmission has finished. Input and output (I/O) operations on a computer can be extremely slow compared to the processing of data.
What is a CGI Script?
A CGI script is any program that runs on a web server.
//There is no window object like browser console. We can use like this as global.
i.e, a = 2; window.a replaced by global.a
//There is also not document object or html document like browser console. We can use like this as process
i.e, process
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//HTTP Module
-> In the first form, you create an http object in your code (totally clean), then, the interpreter will look for each possible import in http module and append it, one by one, to the http object in your code, this is a little slower (not much) than the second form where you are getting the module.exports object defined in the http module, then copying this reference to a new http object in your code, this is object in a node special function with a particular context, not only an object created in your code with the contents of the module.
-> The http API that's baked into Node.js, on the other hand, is just the http module: it can set up HTTP connections and send and receive data, as long as it uses the hypertext transfer protocol (with the relevant HTTP verb).
//v.01
var http = require("http");
var port = 3000;
http.createServer(function(request, response){
response.writeHead(200, {"content-type":"text/html"});
response.write("Alhamdulillah");
response.end();
}).listen(port);
console.log("Server is working on :" + port);
//v.02
var http = require("http");
var port = 3000;
var server = http.createServer(function(request, response){
response.writeHead(200, {"content-type":"text/html"});
response.write("Alhamdulillah");
response.end();
});
server.listen(port);
console.log("Server is working on :" + port);
//v.03
var http = require("http");
var port = 3000;
var requestListener = function(request, response){
response.writeHead(200, {"content-type":"text/html"});
response.write("<h1>Alhamdulillah</h1>");
response.end();
};
var server = http.createServer(requestListener); //Server Creation
server.listen(port, function(){
console.log("Server is running on port:" + port); //The web server will run on this port
});
//File System
//v.01
var fs = require('fs');
console.log("Step 1");
fs.readFile('redme.txt', function(error, data){
console.log("File info"+ data);
});
console.log("Step 2");
//v.02 ,Synchronously file reading
var fs = require('fs');
console.log("Step 1");
var employee = fs.readFileSync('redme.txt', 'utf-8');
console.log(employee);
console.log("Step 2");
//v.03
var fs = require('fs');
console.log("Step 1");
var employee = fs.readFileSync('employee.txt', 'utf-8');
//var employee = fs.readFileSync('employee.json', 'utf-8');
var fileInfo = JSON.parse(employee);
//console.log(employee);
console.log("Name: " +fileInfo.name+ " and " + "Id: " +fileInfo.id);
//v.01, Ascynchronously file writing
var fs = require('fs');
console.log("Step 1");
fs.writeFile('bablu.txt', 'This is Faruk Ahmed Bablu',function(){
console.log("I am writing about myself...");
});
//v.02, Ascynchronously file writing
var fs = require('fs');
console.log("Step 1");
fs.writeFileSync('bablu.txt', 'Hi....');
var about = fs.readFileSync('bablu.txt', 'utf-8');
console.log(about);
//Custom Module
//v.01
var http = require("http");
var about = require("./bab");
var port = 3000;
http.createServer(function(request, response){
response.writeHead(200, {"content-type":"text/html"});
response.write(about.name);
about.myFun();
response.end();
}).listen(port);
console.log("Server is working on :" + port);
//
module.exports = {
name : "Md. Bablu Mia",
myFun : function(){
console.log("This is my fun");
}
};
/*
var name = "Md. Bablu Mia";
var myFun = function(){
console.log("This is my fun");
};
module.exports.name = name;
module.exports.myFun = myFun;
*/
//v.02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment