NodeJs Tutorials
- NodeJs
- Install NodeJs
- Why use NodeJs
- NodeJs Process Model
- create First Application
- Run NodeJs Application
- Node.js Console
- Node.Js Modules
- URL Modules
- node.js Callback
- Node.js Events
- Upload Files
- Upload single & Multiple Files
- NodeJs File System
- NodeJs Email
- Debugging NodeJs
- .ENV
- NodeJs Mysql
- Helpers
- encription and decription in nodeJs
- Query string
- Date & Time
- Express Js
- Template Engine with Express
- MVC Pattern in Node.Js
- list of NPM Module
- Middleware
- Body Parser
- Render
- Nodemon module
- Morgan module
- Flash Message in ExpressJs
- Session
- Session store in database
- Cookies
- Helmet
- Multer
- Router: How To Use Routing In Node.Js
- App.Js
- express.json() and express.urlencoded()
- REST APIs in NodeJs
- Gloabal Objects
- Submit Form Data
- How to get Post Data in Node.js
- How to Get URL Parameters in Node.js
- How to create Node Project
- How to Insert Form Data Into the MySql Table Using Node.js
- How to fetch Data from MySQL database table using Node.js
- CRUD Example
- Await and Async
- Promises
- Login Example
- Password Encription
- How to validate Form (Form Validation) in Node.Js?
- Registration & Login form usingn Node.Js & MySql?
- Forgot & Reset Password
- File Upload in Node.Js with ExpressJs
- Resize Image Before Upload using Multer Sharp
- Upload multiple file using node.js with multer module
- Upload file using node.js with multer module
- Client IP Address
- REST API Downloading File in NodeJs
- Export and Download CSV From MySQL Database
- CRUD REST API
- CRUD REST API Example 2
- Enable HTTPS using Node
- How to send EMAIL using NodeJs?
- Dynamic dependent dropdown using NodeJs?
- Autocomplete Search
- Get and Send Data From Ajax Request
- Get and Post Data using Ajax
- Passport Authentication
- Node Js Data type
- Node Js Error
- Node Js Array Function
- Node Js String Function
- Puppeter Module
What is NodeJs?
__filename
The __filename represents the filename of the code being executed. it return the name of the file.
File Name :
console.log( __filename );
__dirname
The __dirname represents the name of the directory that the currently executing script resides in.
File Name :
console.log( __dirname );
setTimeout(cb, ms)
The setTimeout(cb, ms) global function is used to run callback cb after at least ms milliseconds.
File Name :
function say_hello() {
console.log( "Hello, Ittutorial!");
}
// Now call above function after 5 seconds
setTimeout(say_hello, 5000);
clearTimeout(t)
The clearTimeout(t) global function is used to stop a timer that was previously created with setTimeout().
File Name :
function say_hello() {
console.log( "Hello, Sana!");
}
// Now call above function after 2 seconds
var obj = setTimeout(say_hello, 2000);
// Now clear the timer
clearTimeout(obj);
setInterval(cb, ms)
The setInterval(cb, ms) global function is used to run callback cb repeatedly after at least ms milliseconds.
File Name :
function say_hello() {
console.log( "Hello, Sana!");
}
// Now call above function after 2 seconds
setInterval(say_hello, 2000);
Console
Node.js console is a global object and is used to print different levels of messages to stdout and stderr.
File Name :
console.log([data][, ...])
console.info([data][, ...])
console.error([data][, ...])
console.warn([data][, ...])
console.dir(obj[, options])
console.time(label)
console.timeEnd(label)
console.trace(message[, ...])
console.info("Program Started");
var counter = 10;
console.log("Counter: %d", counter);
console.time("Getting data");
//
// Do some processing here...
//
console.timeEnd('Getting data');
console.info("Program Ended")
Process
The process object is a global object and can be accessed from anywhere. There are several methods available in a process object.
File Name :
Process Events
The process object is an instance of EventEmitter and emits the following events
File Name :
exit
beforeExit
uncaughtException
Signal Events
process.on('exit', function(code) {
// Following code will never execute.
setTimeout(function() {
console.log("This will not run");
}, 0);
console.log('About to exit with code:', code);
});
console.log("Program Ended");
File Name :
// Printing to console
process.stdout.write("Hello World!" + "\n");
// Reading passed parameter
process.argv.forEach(function(val, index, array) {
console.log(index + ': ' + val);
});
// Getting executable path
console.log(process.execPath);
// Platform Information
console.log(process.platform);
Methods :-
File Name :
abort()
chdir(directory)
cwd()
exit([code])
getgid()
setgid(id)
getuid()
setuid(id)
getgroups()
setgroups(groups)
initgroups(user, extra_group)
kill(pid[, signal])
memoryUsage()
nextTick(callback)
umask([mask])
uptime()
hrtime()
File Name :
// Print the current directory
console.log('Current directory: ' + process.cwd());
// Print the process version
console.log('Current version: ' + process.version);
// Print the memory usage
console.log(process.memoryUsage());