Express.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| (Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt) | |||
| Zeile 33: | Zeile 33: | ||
}); | }); | ||
</pre> | </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> | |||
==MVC in Express.js== | |||
* Express.js | |||
* orm : Sequelize | |||
* Template : pug | |||
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). | ||
Aktuelle Version vom 15. Oktober 2024, 15:13 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
MVC in Express.js
- Express.js
- orm : Sequelize
- Template : pug
Hinweis: Diese Inhalte wurden mit Unterstützung von Künstlicher Intelligenz erstellt und redaktionell überprüft (Transparenzhinweis gemäß Art. 50 EU AI Act).