Git Product home page Git Product logo

node-intro-again's Introduction

Back to node js again...

This is a run time environment for javascript to use javascript outside the browser.

By "RYAN DAHL."

we can define node js as :

 node js = (google chrome's engine created in c++) V8 engine + javascript repper code

Steps to begin :

  • install node js for your os
  • check the installation if err
  • get basic understanding of npm "nahi pta mujhe"
  • create new node js file with the command
this will ask some questions related to project
npm init
this will build your packege.json file
npm init -y
  • understand how to read out the docs go to nodejs.org/docs
  • be familiar with moduls like
//  file system, http, many more;

File system module :

const fs = require("fs");
You need to learn how :
  • you can write/create a file
fs.writeFile("filename.ext","data",callback(err));

callback for handle error in between the process.

  • appending text to the file
fs.appandFile("filename.ext","data",callback(err));
  • rename file
fs.rename("filename.ext","newNameToFile",callback(err));
  • copy file
fs.copyFile("firstfilenameOrPath","secondfilenameOrPath",callback(err));

Data of first file will be copied into the second file if everything heppn correctly or it will show specific error message.

  • deleting a file
fs.unlink("filename.ext",callback(err));
  • deleting an empty directory (we can use "rm" or "rmdir")
fs.rm("directorypath",callback(err));
  • deleting a directory with files (we can use "rm" or "rmdir")
fs.rm("directorypath",{recursive:true},callback(err));

this recursive is an optional argument, which is importent for delete the directory with files.

Http module :

you need to unerstand following topics to step up -
const http = require('http');
  • creating server with the help of HTTP module of node js
//server via http method ✅
const http = require('http');
http.createServer((req,res)=>{
  res.writeHead(200,{content_type:"plane/text"});
  res.end("hello sir ... server is created by traditional http method");
}).listen(3000,()=>{
  console.log('on http://localhost:3000/');
})

NPM :

  • installing npm packeges
npm install packegename

or we can only use i to indicate install keyword

  • uninstalling npm packeges
npm uninstall packegename
  • installing particular version for specific packege
npm i packegename@version

Node module folder

whenever  you install any packege for particular work, it will install another required packeges for proper functioning of that packege into node module folder as well.

Hence :

  • Dependencies : are these packeges & another required packeges for proper functioning of the application.

  • Devdependencies : are those packeges, which are used in development phase only.

Expres :

  • create a server with express in an easy way then http method
// server via express method ✅

const express = require("express")
const app = express()
app.get("/",(req,res)=>{
  res.send("hello sir.. server is created by express")
}).listen(3000,()=>{
  console.log("check on http://localhost:3000");
})

Enough for today✅

node-intro-again's People

Contributors

mrkuldeep01 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.