Sarrafa Sigar da Shiga cikin Tsarin Aiwatar da Node.js

A cikin tsarin tura Node.js, sarrafa sigar da shiga sune mahimman al'amura don kiyaye kwanciyar hankali da sarrafa canje-canje a cikin aikace-aikacen. A cikin wannan labarin, za mu bincika yadda ake sarrafa sarrafa sigar da shiga cikin aikin Node.js da kuma samar da takamaiman misalai don kwatanta ra'ayoyin.

Sarrafa sigar tare da Git

Git sanannen kuma tsarin sarrafa sigar rarrabawa mai ƙarfi(DVCS). Linus Torvalds ne ya haɓaka shi a cikin 2005, Git ya zama kayan aiki mai mahimmanci a cikin hanyoyin haɓaka software na zamani.

Tare da Git, zaku iya waƙa da yin rikodin kowane canji a lambar tushen aikin ku. Wannan tsarin yana ba ku damar yin aiki a lokaci ɗaya akan rassan da yawa, yana ba masu haɗin gwiwa damar yin aiki da kansu ba tare da rikice-rikice ba. Kuna iya ƙirƙira, canzawa, haɗawa, da share rassan cikin sauƙi, ba ku damar haɓaka fasali daban-daban, gyare-gyaren kwaro, da nau'ikan aikin a lokaci guda.

Ƙaddamar da wurin ajiya

git init

Ƙirƙirar da sauya rassan

git branch feature-branch  
git checkout feature-branch  

Haɗa rassa da magance rikice-rikice

git merge feature-branch

Tagging for versioning

git tag v1.0.0

Shiga tare da Winston

Winston babban ɗakin karatu ne mai ƙarfi kuma mai dacewa don aikace-aikacen Node.js. Yana ba da tsari mai sassauƙa da daidaitacce wanda ke ba masu haɓaka damar kamawa da adana rajistan ayyukan ta hanyoyi da wurare daban-daban.

Tare da Winston, zaku iya shiga cikin sauƙi cikin saƙonni tare da matakan tsanani daban-daban, kamar gyara kuskure, bayanai, faɗakarwa, kuskure, da ƙari. Yana goyan bayan jigilar shiga da yawa, gami da na'ura wasan bidiyo, fayiloli, bayanan bayanai, da sabis na waje kamar MongoDB, Elasticsearch, da syslog.

Shigar da Winston

npm install winston

Saita da amfani da logger

const winston = require('winston');  
const logger = winston.createLogger({  
  transports: [  
    new winston.transports.Console(),  
    new winston.transports.File({ filename: 'app.log' })  
  ]  
});

Tsarin log da matakan log

logger.format = winston.format.combine(  
  winston.format.timestamp(),  
  winston.format.json()  
);  
logger.level = 'info';

Shiga zuwa fayil ko database

logger.info('This is an informational log message.');  
logger.error('An error occurred:', error);

Haɗa Sarrafa Sigar da Shiga cikin Tsarin Aiwatarwa

Haɗa Git da npm don sarrafa sigar

npm version patch  
git push origin master --tags

Yin amfani da kayan aikin shiga don bin diddigin ayyuka da canje-canje yayin turawa.

 

Ƙarshe: Sarrafa sigar da shigarwa sune mahimman abubuwan haɗin gwiwa a cikin tsarin tura Node.js. Yin amfani da Git don sarrafa sigar yana taimakawa bin canje-canje da sarrafa rassan lambar tushe. Bugu da ƙari, yin amfani da Winston don shiga yana ba da mahimman bayanai game da ayyuka da canje-canje yayin aikin turawa. Haɗa duka biyun a cikin aikin turawa yana tabbatar da kwanciyar hankali da amincin aikace-aikacen ku na Node.js.