Basic of  Node js

Basic of Node js

What is node js?

  • Node js is an JavaScript runtime environment that executes JavaScript code outside of a web browser.
  • It is built on the Google Chrome V8 JavaScript runtime engine. The same engine which compile our js code on browser

Why node js?

  • If you like to code backend in js then node js is your friend
  • Modules/Packages: Node.js has npm, a node package manager, with a library of over 350,000 packages to help get your project or application off the ground with efficiency and ease.
  • Non blocking I/O model / Event Driven

What can node js do ? and example

  • API's and servers
  • Databases (yes some DB's are built in Node)
  • CLI'sBuild Tools
  • AutomationsBasic
  • ScriptingGPU shopping bots 👀

Global in node js

In node js it can be understood as the window in browser.what is defined globally for that we don't need to import any packages .

Example :- __dirname ,__filename,Process,Export,Import ,require

Module

What are modules ?

  • module is pre written chunk of code and it can be a single file or more than one file that you use in your code
  • Module are two type :- Internal module, External module

What is internal module ?

  • Internal module are the built in module by node js and we don't need to install it

Like fs module ,url etc

Importing module

  • There are two method you can import or use javascript code written in different file / folder
  • Common js - const name = require('file/folder relative path' )
  • Module way :-import('file/folder relative path' )

What is fs module ?

  • This is the internal module provide by node js to interact with files
  • Some of the method are :-
  • fs module for read and write

  1. readFile
  2. writeFile
  3. readFileSync
  4. writeFileSync

Package

  • What is packages and what is the use of it?
  • Packages are the collection of module .
  • Which perform some specified task
  • Like express is backend framework ,open ,body-parser parse the incoming request etc
  • 💡 npm (node package manager ) ut manage the different version of pacakge
  • Why do we need package.json file and how to create ?

npm init // while running in terminal  it ask a bunch of questions 
and you want to ignore  those questions just type
npm init -y         

Package.json

whenever we work on the node js ,it provide all the information about pacakges , version and script to run in terminal. etc

How to install packages ?

npm install pacakge-name
or 
npm i pacakge-name         

How to uninstall package?

npm uninstall pacakge-name
or 
npm i pacakge-name        

Hopefully you have learnt something and i would like listen from you any suge

To view or add a comment, sign in

More articles by Sameer Alam

  • Web Server in Node Js

    What is web server ? General concept Before getting into the actual definition of server, let's understand the meaning…

Explore content categories