What is NodeJS and what is MEAN
NodeJS = asynchronous event driven JavaScript runtime, Node is designed to build scalable network applications. In the following "hello world" example, many connections can be handled concurrently. Upon each connection the callback is fired, but if there is no work to be done Node is sleeping *******It has a built in HTTP server library --- you don't need a separate web server like Apache --- the nodeJS application can do the http listening -----*********************** simple NodeJS application that is an http listener and always returns Hello World
This is in contrast to today's more common concurrency model where OS threads are employed. |
|
WHY NodeJS?
Single Thread with Event Loop-->speed
There are a couple of implications of this apparently very simple and basic model
● Web application
● web socket app
● Ad server
● Proxy server
● Streaming server
● Fast file upload client
● Any Real-time data apps
● Anything with high I/O
● chat/messaging
● realtime applications
● high concurrency applications
● communication hubs
● recommendation systems
● MORE MORE MORE
|
2 Ways to create a module
module.exports = { sayHelloInEnglish: function() { return "HELLO"; }, sayHelloInSpanish: function() { return "Hola"; } };
// greetings.js var exports = module.exports = {}; exports.sayHelloInEnglish = function() { return "HELLO"; }; exports.sayHelloInSpanish = function() { return "Hola"; };
how to import (require) a module into a NodeJS file
The keyword
// main.js var greetings = require("./greetings.js"); // "Hello" greetings.sayHelloInEnglish(); // "Hola" greetings.sayHelloInSpanish();
require
returns an object, which references the value ofmodule.exports
for a given file
how to install a module in your application director
$npm install <module name>