Nodejs
↦Node.js is an open-source server environment
↦Node.js allows you to run JavaScript on the server.
Its help to the user to connect the server and Database likely it works as an intermediate
A lot of youth aspires to be a most sought after software developer and so goes on to learn the required programming skills to match to the current market and industrial needs. They have broadly two choices to make
To Be A Front-End Developer
To Be A Back-end Developer.
Node js is a backend develop language. if you want to become a Back-end Developer so you have to study this. It's really hard but if you study hard you will get it soon.
This server-side application directly interacts with the database via an application programming interface (API), which pulls, saves, or changes data.
Node.js which is the most sought after backend scripting language in the current technology market and is becoming the preferred language options for back-end programmers.
Node.js an asynchronous event-driven JavaScript runtime, which is designed to build scalable network applications. It can handle many concurrent connections at a time, where when connection request are made concurrently for each connection a callback is fired. If there is no task to be performed Node will go to sleep.
History of Node.js
Node.js was first conceived in 2009 by Ryan Dahl and was developed and maintained by Ryan which then got sponsored and supported by Joyent. Dahl was not happy the way Apache Http server used to handle a lot of concurrent connections and the way code was being created which either blocked the entire process or implied multiple execution stacks in the case of simultaneous connections. This leads him to create a Node.js project which he went on to demonstrate at the inaugural European JSConf on November 8, 2009. He used Google Google’s V8 JavaScript engine, an event loop, and a low-level I/O API in his project which won lots of hearts and a standing ovation.
Here is how Node.js handles a file request:
- Sends the task to the computer's file system.
- Ready to handle the next request.
- When the file system has opened and read the file, the server returns the content to the client.
What Can Node.js Do?
- Node.js can generate dynamic page content
- Node.js can create, open, read, write, delete, and close files on the server
- Node.js can collect form data
- Node.js can add, delete, modify data in your database.
Step #1:
sudo apt-get update
Step #2:
sudo apt-get install build-essential libssl-dev
Step #3:
sudo curl https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
Step #4 (if no curl):
sudo apt-get install curl
https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
Step #4:
source ~/.profile
Step #5:
nvm --version
Step #6:
nvm install 6.16.0
Step #7:
nvm ls
Step #8:
node --version
Step #9:
npm --version
to install nodemon
:--npm install -g nodemon
Basic commands for the Nodejs
exports.log = {
console: function(msg) {
console.log(msg); },
file: function(msg) {
// log to file here }
}
to export module for define by usersome modules:
http : http includes classes, methods to create Node.js http server.
url : url module includes methods for URL resolution and parsing.
querystring : querystring module includes methods to deal with query string.
path : path module includes methods to deal with file paths.
fs : fs module includes classes, methods, and events to work with file I/O.
util : util module includes utility functions useful for programmers.
to create server:
var http = require('http'); // 1 - Import Node.js core module
var server = http.createServer(function (req, res) { } );
// 2 - creating server //handle incomming requests here..
Url module:
var url = require('url');
var adr = 'http://localhost:8080/default.htm?year=2017&month=february';
var q = url.parse(adr, true);
console.log(q.host); //returns 'localhost:8080'
console.log(q.pathname); //returns '/default.htm'
console.log(q.search); //returns '?year=2017&month=february'
var qdata = q.query; //returns an object: { year: 2017, month: 'february' }
console.log(qdata.month); //returns 'february'
No comments:
Post a Comment