NodeJs: Instalando o NodeJs no Linux: Difference between revisions

From Wiki
No edit summary
Line 55: Line 55:


[[Image:nodejs_helloworld.png]]
[[Image:nodejs_helloworld.png]]
= Instalando o Nginx =
Vamos instalar o Nginx e Node Package Manager (NPM)
1. Abra um terminal
2. Instale o Nginx
'''Fedora.'''
$ sudo dnf -y install nginx
'''Red Hat® Enterprise Linux® / RHEL, CentOS'''
$ sudo yum -y install nginx
Execute o comando
systemctl start nginx
3. Configurar





Revision as of 23:20, 12 September 2015


Instalando o NodeJs

Vamos instalar o NodeJs e Node Package Manager (NPM)

1. Abra um terminal

2. Instale o NodeJs

Fedora.
$ sudo dnf -y install nodejs npm
Red Hat® Enterprise Linux® / RHEL, CentOS
$ sudo yum -y install nodejs npm

3. Para compilar e instalar pacotes adicionais

Fedora.
$ sudo dnf -y install gcc-c++ make
Red Hat® Enterprise Linux® / RHEL, CentOS
$ sudo yum -y install gcc-c++ make

Criando o primeiro programa NodeJs

Para testar vamos criar um programa Hello World

1. Em um editor de texto, crie o arquivo helloworld.js, e digite o código abaixo:

// Hello World - Ebasso.net
 // Carregando a biblioteca HTTP do Node.js.
 var http = require('http');
 // Criando um servidor web para tratar as requisicoes
 var httpServer = http.createServer(function (request, response) {
    // Definindo o Header
    response.writeHead(200, {'Content-Type': 'text/html'});
    // Escreve uma mensagem de resposta do servidor.
    response.write('<html><body><h1>NodeJs on ebasso.net</h1><h2>Hello World!</h2></body></html>');
    // Enviando uma resposta para o cliente
    response.end();
 });
 // Colocando a aplicação/servidor para escutar na porta 8080
 httpServer.listen(8080);
 // Imprime mensagem no terminal do servidor.
 console.log('Servidor Node.js em execucao -  on http://localhost:8080');

Salve e feche o arquivo

2. Executando

node helloworld.js

3. Com um browser acesse a url http://localhost:8080.

File:Nodejs helloworld.png


Ver também