NodeJS da npm, girkawa a Ubuntu 20.04 | 18.04

game da nodejs

A cikin labarin na gaba zamuyi la'akari da yadda zamu iya shigar Node.js da npm akan Ubuntu 20.04 | 18.04. Wannan hanyar buɗewa ce, yanayin giciye-dandamali na lokacin gudu don JavaScript da aka riga aka tattauna a ciki wannan page kuma wannan yana amfani da samfurin Aikin I / O mai daidaitaccen yanayi, wanda yasa ya zama mai sauƙi da inganci.

NodeJS shine Tsarin sabar bude tushen sabar JavaScript wanda aka fi amfani dashi don gina aikace-aikacen uwar garken baya tare da lokacin gudu na JavaScript. Ya dogara ne akan injin VS JavaScript na Chrome. Npm shine manajan kunshin tsoho na NodeJS.

Ana amfani dashi galibi don shirye-shiryen asynchronous kuma shine firam mai haske sosai, wanda ya sa ya fi sauri fiye da wasu. Hakanan ya dace da shahararrun tsarin aiki. Daban-daban na aikace-aikace, kamar aikace-aikacen yanar gizo, aikace-aikacen layin umarni, da sauransu, ana iya haɓaka tare da wannan tsarin ta amfani da Ubuntu.

Nara ma'ajiyar NodeJS daga NodeSource

NodeSource shine matattarar matakin ƙira na kamfani wanda ke kulawa kuma ya ƙunshi sabbin sigar NodeJS. Daga NodeSource za mu iya shigar da takamaiman sigar NodeJS.

Don shigar da NodeJS daga NodeSource, kawai gudanar da ɗayan umarni masu zuwa don ƙara takamaiman sigar da ke sha'awar mu. Yin shi dole ne mu sanya curl. Idan ba ku da wannan kayan aikin tukuna, za ku iya shigar da shi tare da umarnin:

sudo apt install curl

Yanzu ga shigar da sabuwar sigar (14 version), a cikin m (Ctrl + Alt T) za mu ƙara wannan PPA:

ƙara repo nodejs 14

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

para shigar da sigar 12, duk abin da zaka yi shine gudanar da umarnin:

reara mahaɗan repoJS 12

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

para shigar da LTS (10 version), PPA don amfani zai kasance:

ƙara repo nodejs 10

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

Bayan ƙara kowane ɗayan waɗannan PPAs, za mu iya shigar da sabon sigar NodeJS daga ma'ajiyar zaɓinmu. Idan muka ƙara wurare da yawa, za a shigar da sabon sigar NodeJS ba LTS ba.

Sanya NodeJS da npm

Don shigarwa, a cikin m (Ctrl + Alt + T) dole ne mu aiwatar da umarnin:

shigar nodejs tare da dacewa

sudo apt install nodejs

Bayan an gama girka, yakamata a girka NodeJS da npm kuma an shirya amfani dasu. Zamu iya amfani da waɗannan dokokin don duba lambar sigar da aka sanya.

node --version

npm --version

Dokokin za su lissafa fasalin shigar da kumburi da npm:

shigar nodejs da npm

Kuna iya duba duk umarnin shigarwa samuwa daga aikin shafin GitHub.

Sanya NodeJS da npm ta hanyar Snap

Wata hanyar girka NodeJS shine ta hanyar gudanarwa fakitin fakitoci. Wannan na iya zama mafi sauki hanyar aikata shi.

Snaps yana da sauƙi don ƙirƙira da shigar da fakitin software. Waɗannan su ne aikace-aikacen da aka haɗa tare da duk abin dogaro don gudana akan duk shahararrun rarraba Gnu / Linux daga gini ɗaya.

para shigar da sabuwar sigar (14 version) a cikin m (Ctrl + Alt T) gudu:

NodeJs 14 shigarwa ta sauri

sudo snap install node --channel=14/stable --classic

Zamu iya shigar da sigar 13 yanada umarnin:

nodeJs 13 shigarwa na gaggawa

sudo snap install node --channel=13/stable --classic

para shigar da sigar 10, Umurnin don amfani zai kasance mai zuwa:

NodeJS 10 shigarwa ta sauri

sudo snap install node --channel=10/stable --classic

Gwada sabar

Don gwada idan an shigar da sabar yanar gizo daidai, bari mu kirkiro fayil din gwaji da ake kira http_server.js a cikin babban fayil ɗinmu ta amfani da editan da muke so:

cd ~/

vim http_server.js

Sa'an nan za mu kwafa da liƙa abubuwan da ke zuwa cikin fayil ɗin:

fayil din gwajin sabar

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Prueba de Nodejs para Ubunlog');
});

server.listen(port, hostname, () => {
  console.log(`Servidor funcionando en http://${hostname}:${port}/`);
});

Bayan wannan, mun adana fayil ɗin. Yanzu muna aiwatar da shi tare da umarni masu zuwa don fara sabar:

node http_server.js

Ya kamata mu ga fitarwa wanda yayi kama da mai zuwa a cikin tashar:

Misali kayan wasan bidiyo

Yanzu idan muka buɗe mashigin da muka fi so kuma muna zuwa sunan mai masauki na sabar ko adireshin IP wanda tashar 3000 ta biyo baya, ya kamata mu ga shafin misali kamar haka:

gwaji a Firefox

http://localhost:3000

para learnara koyo game da NodeJS, masu amfani zasu iya ziyartar shafin aiki.


Abubuwan da ke cikin labarin suna bin ka'idodinmu na ka'idojin edita. Don yin rahoton kuskure danna a nan.

Sharhi, bar naka

Bar tsokaci

Your email address ba za a buga.

*

*

  1. Mai alhakin bayanan: Miguel Ángel Gatón
  2. Dalilin bayanan: Gudanar da SPAM, gudanar da sharhi.
  3. Halacci: Yarda da yarda
  4. Sadarwar bayanan: Ba za a sanar da wasu bayanan ga wasu kamfanoni ba sai ta hanyar wajibcin doka.
  5. Ajiye bayanai: Bayanin yanar gizo wanda Occentus Networks (EU) suka dauki nauyi
  6. Hakkoki: A kowane lokaci zaka iyakance, dawo da share bayanan ka.

  1.   Mateo m

    Ina matukar son yadda aka bayyana shi sosai.
    Gracias !!