Showing Posts From
Npm

- 22 Jan, 2017
- 1 min read
Guide to Installing Node.js on a Raspberry Pi
Node.js is a open source platform to create network applications using JavaScript. The applications are executed on the server and not as usual on the client in the browser. Integrated modules, such as the HTTP-module, enable the realisation of web servers. Additional modules can be simply installed using the supplied package manager npm. Update 04.09.2016: - Added further, alternative guideContent Install Node.js - Option #1 (Raspberry Pi B+ and older)As a first step you need to download the ARM package that is optimised for Node.js.wget http://node-arm.herokuapp.com/node_latest_armhf.debNode.js can now be installed usingsudo dpkg -i node_latest_armhf.debNode.js and the package manager npm are now installed. You can check the installed version unsing node -v. Install Node.js - Option #2 (Raspberry Pi 2/3 and newer)Add the Node.js source to your package list.curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -Node.js can now be installed usingsudo apt-get install -y nodejs You can check the installed version unsing nodejs -v.Test Node.js with a "Hello World" applicationCreate a JavaScript file usingsudo nano helloWorld.js and add the following code:var http = require('http'); http.createServer(function (request,response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello World!\n'); }).listen(8000) console.log('Web Server running at http://127.0.0.1:8000');Execute the script with:node helloWorld.jsOpen the browser and go to the address.http://IP-Adresse-des-Raspberry:8000/

- 13 May, 2015
- 2 Min. Lesezeit
Node.js auf dem Raspberry Pi installieren
Node.js ist eine Open-Source-Plattform, zum erstellen von Netzwerkanwendungen die in JavaScript geschrieben werden. Die Anwendungen werden Server-seitig ausgeführt und nicht wie "normal" Client-seitig im Browser. Integrierte Module wie z.B. das HTTP-Modul, ermöglichen die Realisierung von Webserver. Weitere Module können einfach mit dem Paketmanager npm installiert werden. Update 16.03.2020: - Variante 1 für ARM6 Chip aktualisiert Update 04.09.2016: - weitere Variante hinzugefügtInhalt Node.js installieren Variante #1 (ARM6: Raspberry Pi B+, Raspberry Pi Zero und älter)Prüfe mit dem Befehl uname -m ob dein Raspberry Pi einen ARM6 Chip hat. Der Befehl sollt etwas wie armv6l ausgeben.Lade dir das ARM6 optimierte Node.js installations Paket herunter. Node.js v8.x:wget https://nodejs.org/dist/latest-v8.x/node-v8.17.0-linux-armv6l.tar.xz Node.js v10.x:wget https://nodejs.org/dist/latest-v10.x/node-v10.19.0-linux-armv6l.tar.xzEntpacke das Archiv.tar xvf node-v8.17.0-linux-armv6l.tar.xz # oder tar xvf node-v10.19.0-linux-armv6l.tar.xzWechsel in den Ordner wohin du die Dateien entpackt hast...cd node-v8.12.0-linux-armv6l/ # oder cd node-v10.19.0-linux-armv6l/... und kopiere die Node.js und NPM Dateien in die System Ordner /usr/bin/ und /usr/lib/sudo cp -R bin/* /usr/bin/ && sudo cp -R lib/* /usr/lib/Node.js und der Paketmanager npm sind nun installiert. Mit node -v und npm -v kannst du überprüfen welche Version installiert ist. Node.js installieren Variante #2 (Raspberry Pi 2 / 3 und neuer)Node.js Quelle zu deinen Paketlisten hinzufügen. Node.js v6.x:curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - Node.js v8.x:curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - Node.js v10.x:curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - Node.js v11.x:curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash - Wenn du die folgende Fehlermeldung folge den Schritten für ältere Raspberry Pi Modelle. "You appear to be running on ARMv6 hardware. Unfortunately this is not currently supported by the NodeSource Linux distributions. Please use the ‘linux-armv6l’ binary tarballs available directly from nodejs.org for Node.js v4 and later."Jetzt kannst du Node.js mit folgendem Befehl installieren.sudo apt-get install -y nodejs Mit nodejs -v kannst du überprüfen welche Version installiert ist.Node.js testen mit einem Hello World ProgrammErstelle eine Javascript Datei mitsudo nano helloWorld.js und füge folgenden Javascript Code hinein.var http = require('http'); http.createServer(function (request,response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello World!\n'); }).listen(8000) console.log('Web Server running at http://127.0.0.1:8000');Führe das Script ausnode helloWorld.jsÖffne den Browser und rufe folgende Adresse auf.http://IP-Adresse-des-Raspberry:8000/