Express.js: Unterschied zwischen den Versionen

Aus Dokument
Zur Navigation springen Zur Suche springen
// via Wikitext Extension for VSCode
 
Zeile 32: Zeile 32:
     console.log(`Example app listening at unix:${path}`);
     console.log(`Example app listening at unix:${path}`);
});
});
</pre>
<pre>
your-project/
├── models/
│  ├── user.js
│  └── product.js
├── controllers/
│  ├── userController.js
│  └── productController.js
├── views/
│  ├── index.pug
│  └── users.pug
├── routes/
│  ├── users.js
│  └── products.js
├── app.js
└── package.json
</pre>
</pre>


Hinweis: Diese Inhalte wurden mit Unterstützung von Künstlicher Intelligenz erstellt und redaktionell überprüft (Transparenzhinweis gemäß Art. 50 EU AI Act).
Hinweis: Diese Inhalte wurden mit Unterstützung von Künstlicher Intelligenz erstellt und redaktionell überprüft (Transparenzhinweis gemäß Art. 50 EU AI Act).

Version vom 15. Oktober 2024, 14:06 Uhr

Hinweis: Diese Inhalte wurden mit Unterstützung von Künstlicher Intelligenz erstellt und redaktionell überprüft (Transparenzhinweis gemäß Art. 50 EU AI Act).

Expres.js ist ein Webanwendungsframework für Node.js. Es ist Open Source und wurde von TJ Holowaychuk entwickelt. Express.js ist das beliebteste Node.js-Framework und wird von vielen Entwicklern verwendet.

Installation

Um Express.js zu installieren, führen Sie den folgenden Befehl aus:

mkdir express-app
cd express-app
npm init
npm install express

Beispiel

Hier ist ein einfaches Beispiel für eine Express.js-Anwendung:

const express = require('express');
const fs = require('fs');
const path = '/tmp/express.sock';

const app = express();

// Entfernen Sie den Socket, falls er bereits existiert
if (fs.existsSync(path)) {
    fs.unlinkSync(path);
}

app.get('/', (req, res) => {
    res.send('Hello World!');
});

app.listen(path, () => {
    fs.chmodSync(path, '777'); // Optional: Setzen Sie die Berechtigungen für den Socket
    console.log(`Example app listening at unix:${path}`);
});
your-project/
├── models/
│   ├── user.js
│   └── product.js
├── controllers/
│   ├── userController.js
│   └── productController.js
├── views/
│   ├── index.pug
│   └── users.pug
├── routes/
│   ├── users.js
│   └── products.js
├── app.js
└── package.json

Hinweis: Diese Inhalte wurden mit Unterstützung von Künstlicher Intelligenz erstellt und redaktionell überprüft (Transparenzhinweis gemäß Art. 50 EU AI Act).