-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode_text.txt
149 lines (103 loc) · 3.1 KB
/
Node_text.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
What is Server Side Scripting?
Various Server Side Scripting Technologies
Node.js
- It is a server side script technology that run on V8 compiler.
- It is JavaScript Based
- It uses Async techniques
- No Buffering
- It sends data in form of packet.
- It is single threaded
- Not good for CPU intensive apps.
- It is faster as it is single threaded.
- Not good for ERP.
- Good for audio and video streaming apps.
# Setup Environment for Node.js
1. Download and Install Node.js
2. Test >node -v >npm -v
# Server Side Objects
1. Request
2. Response
3. Session
4. Application
5. Cookie
6. OS
7. FS
8. Server
9. Memory Stream
# Server Side Techniques
1. Model Binding
2. Data Binding
3. Routing
4. Security
5. Buffering
# Language
1. JavaScript
Note: JavaScript is used only for REPL and Language Features.
No DOM manipulations.
R - Read
E - Evaluate [Expressions]
P - Print
L - Loop
document.write() // invalid
alert()
prompt()
innerHTML etc..
# Node REPL Terminal:
- It provides a terminal to run node.js commands
- You can also run REPL.
- To open REPL terminal
C:\> node
>
# Node.js Programs
- Every node.js program is a JavaScript program stored in ".js" file.
- You can compile and run by using node compiler.
Ex:
hello.js
console.log("Hello ! Node.js");
C:\> node hello.js
# Node.js Server Side Program Structure:
1. Download and Install every module that your want to use in application.
[ Node.js comes with only core module - others you have to download ]
2. Import module into program by using "require()".
var refName = require("ModuleName");
refName.Class
refName.function()
refName.property
3. Implement the classes and functions to define a functionality.
Node FS Module
=============
- Node "File Stream" module provides a set of properties and methods that are used to access and control files on server.
1. Install FS module in your project
> npm install fs --save
2. Write the following program
"index.js"
var fs = require("fs");
console.log("Read Started");
var data = fs.readFileSync("../data/help.txt");
console.log(data.toString());
console.log("Read Completed");
> node index.js
Note: Node.js is using synchronous technique for executing the tasks.
Ex: Async Reading
var fs = require("fs");
console.log("Read Started");
fs.readFile("../data/help.txt", function(err, data){
if(!err){
console.log(data.toString());
} else {
console.log(err);
}
})
console.log("Read Completed");
Node OS Module
=======================
- It provides a set of properties and methods that are used by server to access the information about OS running on Server.
cpus() It returns the CPU structure.
Syntax:
var os = require("os");
console.log(os.cpus());
freemem Free memory
totalmem Total memory
Ex:
var os = require("os");
console.log(` Free Memory : ${os.freemem} \n Total : ${os.totalmem}`);