# OpenFaas Node.js Funktion deployen

Heute deployen wir eine Node.js Funktion in unser OpenFaas. Wenn Du die CLI noch nicht installiert hats, kannst Du es mit diesem Befehl nachholen:
npm install --global @openfaas/faas-cli
Außerdem musst Du dich an deinem OpenFaas anmelden:
export OPENFAAS_URL=ip-addr-vom-server:8080
faas login --username admin --password admin-passwort
Danach können wir unsere erste Funktion schreiben. Dazu dürfen wir uns erst einmal ein Template erstellen oder ein Standard Templates (opens new window) auswählen. Ich wähle hierzu das node14 Standard Template:
faas new --lang node14 hellofaas
Die CLI wird ein paar Dateien anlegen:
template/**
hellofaas/handler.js
hellofaas/package.json
hellofaas.yml
Wir öffnen die Datei hellofaas/handler.js um unser Funktion anzupassen:
'use strict'
module.exports = async (event, context) => {
const result = 'hello faas';
return context.status(200).succeed(result)
}
Passe in der hellofaas.yml den image Eintrage an (wenn Du noch keiner docker hub Account hats, solltest Du dir nun einen zulegen):
version: 1.0
provider:
name: openfaas
gateway: http://localhost:8080
functions:
hellofaas:
lang: node14
handler: ./hellofaas
image: bjoernrenzel/hellofaas:latest
Danach bauen wir unsere Funktion mit unserem lokalem docker:
faas build -f hellofaas.yml
Nun pushen wir unsere Funktion in unsere lokales Repository:
faas-cli push -f hellofaas.yml
Wenn Dir der Worker erfolg meldet kannst Du danach deine Funktion auf deinem OpenFaas deployen:
faas deploy -f hellofaas.yml
