Friday, March 3, 2017

Cheat sheet for Node

1) Specify starting file for our application

  •  In package.json file we can specify the starting file for our application

  •  In the command prompt type . We did not specify the file to start in the command prompt

C:\Development\NodeProjects\bookstore>npm start

> bookstore@1.0.0 start C:\Development\NodeProjects\bookstore
> node app.js

Running on port 5000

2) Check for mongoose connection state in express

The call to mongoose.model establishes the name of the collection the model is tied to, with the default being the pluralized, lower-cased model name. mongodb collections should be in lowercase

mongoose.connection.readyState specifies the state of the connection

mongoose.set('debug', true);
// test.js
require('./app.js'); // which executes 'mongoose.connect()'

var mongoose = require('mongoose');
Output - 0 = disconnected, 1 = connected, 2 = connecting, 3 = disconnecting

3) Latest stable version of node

4) Short cut to get out from node program

Ctrl + c to get out of node program

5) Use case for node

  • Utilities for machine (Gulp,Grunt, Yomen)
  • REST API's and backend application
  • Real-Time services (Chat, Games, etc)
  • Blogs, CMS, Social applications
  • Move files
  • Listen to HTTP traffic

6 ) Difference between client side java script and node

  • No window object.It has global object.
  • No document object tied to process object

7) Where does the modules get installed in nodejs

  Modules get installed into "node_modules" folder

8 ) Popular Modules for NodeJs

Express : Web development framework
Connect : Extensible HTTP server framework : Server side component for web       sockets
Pug / Jade : Template engine inspired by HAML
Mongo / Mongoose : Wrappers to interact with Mongo DB
Coffee-script : CoffeeScript compiler( super set of JavaScript)
Redis : Redis client library

9) Why is --Save used in command prompt

--Save adds dependencies in project.json

10) What is the importance of package.json

  • Provides meta data
  • Goes in the root of your package/ application
  • Tells NPM how your package is structured and what to do to install it
11) Upgrade the NPM dependencies, after upgrading node
npm install npm@latest -g

No comments:

Post a Comment