Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Express.js Application Structure | Introduction to Express.js
Express.js Essentials for Backend Development

Express.js Application Structure

Свайпніть щоб показати меню

To start building with Express.js, you will usually create a minimal application in a single file called app.js. This file is the entry point of your Express.js project. Here is what a minimal Express.js application looks like:

const express = require('express');
const app = express();

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

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Each part of this file has a specific purpose. The first line, const express = require('express');, imports the Express.js module so you can use its features in your application. The next line, const app = express();, creates an instance of an Express application. This app object is used to define routes and configure your server.

The line app.get('/', (req, res) => { ... }); defines a route handler for HTTP GET requests to the root URL (/). When someone visits your server's homepage, this function runs and sends back the text "Hello, Express!".

Finally, app.listen(3000, () => { ... }); starts the server and tells it to listen for incoming connections on port 3000. The callback function runs once the server is up and running, logging a message to the console.

Express.js applications are typically organized around the main app.js file. As your application grows, you might split your code into multiple files, but the app.js file always serves as the main hub that creates the Express instance, sets up middleware, defines routes, and starts the server.

question mark

Which of the following statements best describes the structure of a basic Express.js application as shown in the app.js file?

Виберіть правильну відповідь

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 2

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Секція 1. Розділ 2
some-alt