Wednesday 29 July 2020

How do I manage MongoDB connections in a Node.js web application?

How do I manage MongoDB connections in a Node.js web application?

Question: How do I manage MongoDB connections in a Node.js web application?
You need to install mongoose and bluebird module.
Also you must have mongodb install in server, As you need mongodb URL and port on which mongodb running.

Example
var mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
//mongodb connection with error handing
mongoose.connect(config.MONGO_DB_URL + config.MONGO_DB);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
    console.log("MongoDB connected Successfully.!");
});




Question: mongoose - find all documents with IDs listed in array?
var AjaxChatUser = mongoose.model('AjaxChatUser');
AjaxChatUser.find({
    '_id': { $in: [
        mongoose.Types.ObjectId('4ed3ede8844f0f351100000c'),
        mongoose.Types.ObjectId('4ed3f117a844e0471100000d'), 
        mongoose.Types.ObjectId('4ed3f18132f50c491100000e')
    ]}
}, function(err, docs){
     console.log(docs);
});



Question: How to npm install to a specified directory?
Use --prefix option, to installed in specific directory.
Example
npm install --prefix  -g



Question: How to declare multiple module.exports in Node.js?
You can put multiple function inside module.exports.

Example
module.exports = {
    method: function() {},
    otherMethod: function() {},
};


Question: Can we write a JS code that work for both (node and the browser)?
Yes, We can write.
Suppose we have mymodule.js which have following code.
Example of Code
(function(exports){
   exports.test1 = function(){
        return 'this is test1 function.'
    };
   exports.test2 = function(){
        return 'this is test2 function.'
    };

})(typeof exports === 'undefined'? this['mymodule']={}: exports);


In Node (Server side()
var share = require('./mymodule.js');
share.test1();
share.test2();


In Browser (Client side()
//Include the js with script tag
share.test1();
share.test2();




Question: How we can use global variable in Node?
We can use with global.varname
global.version='1022.55';



Question: How we can access static files with express.js in Node?
Use following to set the folder as static so that we can put public files here.
app.use(express.static('public')); //public folder




Friday 24 July 2020

Scrum Tutorial - part 2

Scrum Tutorial - part 2

Question: What is Scrum Events?
There are prescribed events that are used in Scrum to create regularity  and these are time-boxed events.
Following are 4 Events.
  1. Sprint planning
  2. Daily scrum
  3. Sprint review
  4. Sprint retrospective


Question: What is Product Backlog?
The Product Backlog is an ordered list of application/software/etc that is known to be needed in the product.
It is the single source of requirements for any changes to be made to the product.
The Product Owner is responsible for the Product Backlog, including its content, availability, and ordering.



Question: What is Sprint Backlog?
The Sprint Backlog is the set of Product Backlog items selected for the Sprint, plus a plan for delivering the product Increment and realizing the Sprint Goal.
The Sprint Backlog is a forecast by the Development Team about what functionality will be in the next Increment


Question: What is Increment?
The Increment is the sum of all the Product Backlog items completed during a Sprint and the value of the increments of all previous Sprints.



Question: What is Definition of DONE?
When a Product Backlog item or an Increment is described as “Done”, everyone must understand what "Done" means.
Before a Product Backlog Item is considered "done" or "complete", it must respect the following criteria (Defination may be similar to below):
--Unit Tests are written and passing
--Acceptance Tests are written and passing
--Accessibility testing using https://wave.webaim.org/
--Continuous Integration (CI) pipeline passing



Question: What is Burn-down Chart?
A chart which shows the amount of work which is thought to remain in a backlog. .



Question: What is Burn-up Chart?
A chart which shows the amount of work which has been completed..



Question: What is Coherent/Coherence?
The quality of the relationship between certain Product Backlog items which may make them worthy of consideration as a whole.



Question: What is Emergence?
The process of the coming into existence or prominence of new facts or new knowledge of a fact, or knowledge of a fact becoming visible unexpectedly.



Question: What is Empiricism?
It has three pillars: transparency, inspection and adaptation.



Question: What is Sprint Retrospective?
Scrum Event that is set to a time-box of 3 hours, or less, to end a Sprint.



Question: What is Technical Debt?
The typically unpredictable overhead of maintaining the product.



Question: What is Artifacts?
An object made by a human being, typically one of cultural or historical interest.



Question: What is Cancelling a Sprint?
A Sprint can be cancelled before the Sprint time-box is over. Only the Product Owner has the authority to cancel the Sprint, although he or she may do so under influence from the stakeholders, the Development Team, or the Scrum Master. 


 
Question: Describe the Scrum Events in Details?
  1. Sprint planning: A time-boxed event occurs at the beginning of a sprint where the team determines the product backlog items they will work.
  2. Daily scrum: A is a 15-minute time-boxed event for the Development Team to synchronize activities and create a plan for the next 24 hours.
  3. Sprint review: A time-boxed event holds at the end of the Sprint to inspect the Increment and adapt the Product Backlog if needed. In this the Scrum Team and stakeholders collaborate about what was done in the Sprint.
  4. Sprint retrospective: Event for providing an opportunity for the Scrum Team to inspect itself and create a plan for improvements to be enacted during the next Sprint.