1.准备 Node.js 应用程序源代码

        1.创建一个名为 nodejs-mongo 的项目目录

[root@host1 multi-build]# cd
[root@host1 ~]# mkdir -p nodejs-mongo
[root@host1 ~]# cd nodejs-mongo
[root@host1 nodejs-mongo]# pwd
/root/nodejs-mongo

        2.在该项目目录下创建 src 子目录以存放源代码

[root@host1 nodejs-mongo]# mkdir -p src
[root@host1 nodejs-mongo]# ls -l
总用量 0
drwxr-xr-x. 2 root root 6  9月 20 23:54 src

        3.在 src 子目录下创建源代码文件 index.js ,并将该文件用作项目主文件

[root@host1 nodejs-mongo]# cd src
[root@host1 src]# pwd
/root/nodejs-mongo/src
[root@host1 src]# vi index.js
[root@host1 src]# cat index.js
const path = require ('path');
const express = require('express');const mongoose = require ('mongoose');const app = express();
app.set('view engine', 'ejs');
app.set('views', path.join( dirname, './views'));app.use(express.urlencoded(t extended:false ));
mongoose
.connect (
'mongodb://mongo:27017/node-mongo', 
( useNewUrlParser: true )
.then(() => console.log('MongoDB 连接成功!))
.catch(err => console.log(err));
const Item = require('./models/item');
app.get('/',(req, res) =>1
Item, find()
.then(items => res.render('index', ( items )))
.catch(err => res.status(404).json(( msg:‘目前还没有任何事项!');
1);
app.post('/item/add',(req, res) =>(
const newItem = new Item(t
name: req.body.name
newItem, save ().then(Item => res.redirect('/'));
const port = 3000;
app.listen(port, () => console.log('服务器正在运行.."));

        4.在 src 子目录下创建 models 子目录,再在 models 子目录下创建一个名为 item.js 的文件来为要存储的条目定义模式并创建模型

[root@host1 src]# mkdir -p models
[root@host1 src]# cd models
[root@host1 models]# vi item.js
[root@host1 models]# cat item.js
const mongoose = require('mongoose');
const { Schema } = mongoose;
const ItemSchema = new Schema({
  name: {
    type: String,
    required: true
  },
  date: {
    type: Date,
    default: Date.now
  }
});
module.exports = mongoose.model('Item', ItemSchema);

        5.在 src 子目录下创建 views 子目录,再在 views 子目录下创建一个名为 index.ejs 的文件来为数据展示提供 EJS 模板引擎

[root@host1 models]# cd /root/nodejs-mongo
[root@host1 nodejs-mongo]# cd src
[root@host1 src]# pwd
/root/nodejs-mongo/src
[root@host1 src]# mkdir -p views
[root@host1 src]# cd views
[root@host1 views]# vi index.ejs
[root@host1 views]# cat index.ejs
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Node.js 事项管理</title>
    <style>
        body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
        form { margin: 20px 0; }
        input[type="text"] { padding: 8px; width: 300px; }
        input[type="submit"] { padding: 8px 20px; background: #007bff; color: white; border: none; cursor: pointer; }
        ul { list-style: none; padding: 0; }
        li { padding: 10px; border-bottom: 1px solid #eee; }
        .empty { color: #666; }
    </style>
</head>
<body>
    <h1>事项管理系统</h1>

    <!-- 添加事项表单 -->
    <form method="post" action="/item/add">
        <label for="name">事项内容:</label>
        <input type="text" id="name" name="name" required>
        <input type="submit" value="添加">
    </form>

    <!-- 事项列表(EJS 渲染部分) -->
    <h3>当前事项:</h3>
    <ul>
        <% if (items && items.length > 0) { %>
            <% items.forEach(function(item) { %>
                <li>
                    <%= item.name %>
                    <small style="color: #999; margin-left: 10px;">
                        <%= new Date(item.createdAt).toLocaleString() %>
                    </small>
                </li>
            <% }) %>
        <% } else { %>
            <li class="empty">暂无事项,请添加新内容~</li>
        <% } %>
    </ul>
</body>
</html>

        6.在项目根目录下创建 package.json 文件,定义项目所需的各种模块以及项目的配置信息。小例中 package.json 文件的内容如下,重点是定义项目运行所需的依赖

[root@host1 views]# cd /root/nodejs-mongo
[root@host1 nodejs-mongo]# pwd
/root/nodejs-mongo
[root@host1 nodejs-mongo]# npm init -y
bash: npm: 未找到命令...
安装软件包“npm”以提供命令“npm”? [N/y] y


 * 正在队列中等待... 
 * 正在载入软件包列表。... 
下列软件包必须安装:
 nodejs-1:16.20.2-8.el9.x86_64JavaScript runtime
 nodejs-docs-1:16.20.2-8.el9.noarchNode.js API documentation
 nodejs-full-i18n-1:16.20.2-8.el9.x86_64Non-English locale data for Node.js
 nodejs-libs-1:16.20.2-8.el9.x86_64Node.js and v8 libraries
 npm-1:8.19.4-1.16.20.2.8.el9.x86_64Node.js Package Manager
继续更改? [N/y] y


 * 正在队列中等待... 
 * 正在等待认证... 
 * 正在队列中等待... 
 * 正在下载软件包... 
 * 正在请求数据... 
 * 正在测试更改... 
 * 正在安装软件包... 
Wrote to /root/nodejs-mongo/package.json:

{
  "name": "nodejs-mongo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}



[root@host1 nodejs-mongo]# npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help init` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (nodejs-mongo) npm WARN init canceled
npm notice 
npm notice New major version of npm available! 8.19.4 -> 11.6.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.6.0
npm notice Run npm install -g npm@11.6.0 to update!
npm notice 
[root@host1 nodejs-mongo]# vi package.json
[root@host1 nodejs-mongo]# cat package.json
{
  "name": "node-mongo",
  "version": "1.0.0",
  "description": "Node.js + Express + MongoDB 事项管理系统",
  "main": "src/index.js",  
  "license": "ISC",
  "scripts": {
    "start": "node src/index.js",  
    "dev": "nodemon src/index.js"  
  },
  "dependencies": {
    "ejs": "^3.1.3",       
    "express": "^4.17.1",  
    "mongoose": "^5.7.1"   
  },
  "devDependencies": {
    "nodemon": "^3.0.1"    
  }
}

2.创建 Dockerfile

[root@host1 nodejs-mongo]# vi Dockerfile
[root@host1 nodejs-mongo]# cat Dockerfile
FROM node:18.0.0-alpine

WORKDIR /usr/src/app
COPY package*.json ./
RUN npm config set registry https://registry.npmmirror.com
RUN npm install --production
COPY . .
EXPOSE 300
CMD ["node", "src/index.js"]

[root@host1 nodejs-mongo]# vi Dockerfile
[root@host1 nodejs-mongo]# cat Dockerfile
FROM node:18.0.0-alpine

WORKDIR /usr/src/app
COPY package*.json ./
RUN npm config set registry https://registry.npmmirror.com
RUN npm install --production
COPY . .
EXPOSE 3000
CMD ["node", "src/index.js"]

3.创建 Compose 文件

[root@host1 nodejs-mongo]# vi compose.yaml
[root@host1 nodejs-mongo]# cat compose.yaml
# 定义 Docker Compose 版本(支持 v2 语法)
version: '3.8'

# 定义所有服务(应用、数据库等)
services:
  # Node.js 应用服务(自定义名称为 app)
  app:
    # 容器名称(自定义,方便识别)
    container_name: node-mongo
    # 重启策略:总是自动重启(如崩溃、服务器重启后)
    restart: always
    # 构建配置:使用当前目录(.)的 Dockerfile 构建镜像
    build: .
    # 端口映射:宿主机器端口:容器内端口(外部通过 3000 访问容器的 3000 端口)
    ports:
      - "3000:3000"
    # 依赖关系:启动 app 前先启动 mongo 服务(确保数据库就绪)
    depends_on:
      - mongo
    # 可选:添加环境变量(如 MongoDB 连接地址,与代码中保持一致)
    environment:
      - MONGO_URI=mongodb://mongo:27017/node-mongo

  # MongoDB 数据库服务
  mongo:
    # 容器名称(自定义)
    container_name: mongo
    # 使用官方 MongoDB 镜像(版本 7.0)
    image: mongo:7.0
    # 端口映射:宿主机器 27017 映射到容器 27017(可选,本地开发时方便直接连接数据库)
    ports:
      - "27017:27017"
    # 数据持久化:将 MongoDB 数据存储到宿主机器的 ./mongo-data 目录(避免容器删除后数据丢失)
    volumes:
      - ./mongo-data:/data/db
    # 重启策略:总是自动重启
    restart: always

4.构建并运行应用程序

[root@host1 nodejs-mongo]# docker compose up --build
WARN[0000] /root/nodejs-mongo/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Running 9/9
 ✔ mongo Pulled                                                                                44.8s 
   ✔ 60d98d907669 Already exists                                                                0.0s 
   ✔ ee4a43a67c8f Pull complete                                                                 2.5s 
   ✔ 811c6fea458c Pull complete                                                                 3.6s 
   ✔ 19de34bf772b Pull complete                                                                 3.6s 
   ✔ 6a36c9da359f Pull complete                                                                 4.9s 
   ✔ 1a55754bdc07 Pull complete                                                                 4.9s 
   ✔ 75830f6890ac Pull complete                                                                39.4s 
   ✔ 178c71294f1b Pull complete                                                                39.5s 
[+] Building 51.0s (13/13) FINISHED                                                                  
 => [internal] load local bake definitions                                                      0.0s
 => => reading from stdin 487B                                                                  0.0s
 => [internal] load build definition from Dockerfile                                            0.0s
 => => transferring dockerfile: 306B                                                            0.0s
 => [internal] load metadata for docker.io/library/node:18.0.0-alpine                           5.7s
 => [internal] load .dockerignore                                                               0.0s
 => => transferring context: 2B                                                                 0.0s
 => [1/6] FROM docker.io/library/node:18.0.0-alpine@sha256:469ee26d9e00547ea91202a34ff2542f98  15.9s
 => => resolve docker.io/library/node:18.0.0-alpine@sha256:469ee26d9e00547ea91202a34ff2542f984  0.0s
 => => sha256:469ee26d9e00547ea91202a34ff2542f984c2c60a2edbb4007558ccb76b56df2 1.43kB / 1.43kB  0.0s
 => => sha256:77f86133ced42635d78a2ca2ab27945f8ac9aa06ef092f52c84bb9b2a13055fc 1.16kB / 1.16kB  0.0s
 => => sha256:de1a9de7d955550de3a7caaa4f6a5085b72b17ec272dc56c13b3a2becba4cab3 6.58kB / 6.58kB  0.0s
 => => sha256:df9b9388f04ad6279a7410b85cedfdcb2208c0a003da7ab5613af71079148139 2.81MB / 2.81MB  1.3s
 => => sha256:4fababc43238082e7fe01f475aeddde0d59ede614ee7bb4a1c27a2e9a86927 46.66MB / 46.66MB  4.0s
 => => sha256:ab29cc3c22467e202fbd625cb34d96af7579d7e146c3df4f9fa394dd97fea079 2.35MB / 2.35MB  2.6s
 => => extracting sha256:df9b9388f04ad6279a7410b85cedfdcb2208c0a003da7ab5613af71079148139       0.3s
 => => sha256:759c4cf4639ec0cc2311e8f83065d24506c9c389c98be50750fa2a70af844c64 449B / 449B      2.1s
 => => extracting sha256:4fababc43238082e7fe01f475aeddde0d59ede614ee7bb4a1c27a2e9a86927be      10.6s
 => => extracting sha256:ab29cc3c22467e202fbd625cb34d96af7579d7e146c3df4f9fa394dd97fea079       0.5s
 => => extracting sha256:759c4cf4639ec0cc2311e8f83065d24506c9c389c98be50750fa2a70af844c64       0.0s
 => [internal] load build context                                                               0.0s
 => => transferring context: 7.04kB                                                             0.0s
 => [2/6] WORKDIR /usr/src/app                                                                  0.5s
 => [3/6] COPY package*.json ./                                                                 0.0s
 => [4/6] RUN npm config set registry https://registry.npmmirror.com                            2.8s
 => [5/6] RUN npm install --production                                                         21.4s
 => [6/6] COPY . .                                                                              1.6s 
 => exporting to image                                                                          0.9s 
 => => exporting layers                                                                         0.9s 
 => => writing image sha256:58dd2f3651b8f3b3ca14bd0a190417e685b55f4142b727bde58c872b0b507168    0.0s 
 => => naming to docker.io/library/nodejs-mongo-app                                             0.0s 
 => resolving provenance for metadata file                                                      0.0s 
[+] Running 4/4
 ✔ nodejs-mongo-app              Built                                                          0.0s 
 ✔ Network nodejs-mongo_default  Created                                                        0.1s 
 ✔ Container mongo               Created                                                        0.1s 
 ✔ Container node-mongo          Created                                                        0.0s 
Attaching to mongo, node-mongo
mongo  | {"t":{"$date":"2025-09-20T16:28:41.676+00:00"},"s":"I",  "c":"NETWORK",  "id":4915701, "ctx":"main","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":21},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":21},"outgoing":{"minWireVersion":6,"maxWireVersion":21},"isInternalClient":true}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:41.685+00:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
mongo  | {"t":{"$date":"2025-09-20T16:28:41.685+00:00"},"s":"I",  "c":"NETWORK",  "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
mongo  | {"t":{"$date":"2025-09-20T16:28:41.690+00:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","namespace":"config.tenantMigrationDonors"}}
mongo  | {"t":{"$date":"2025-09-20T16:28:41.690+00:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","namespace":"config.tenantMigrationRecipients"}}
mongo  | {"t":{"$date":"2025-09-20T16:28:41.690+00:00"},"s":"I",  "c":"CONTROL",  "id":5945603, "ctx":"main","msg":"Multi threading initialized"}
mongo  | {"t":{"$date":"2025-09-20T16:28:41.690+00:00"},"s":"I",  "c":"TENANT_M", "id":7091600, "ctx":"main","msg":"Starting TenantMigrationAccessBlockerRegistry"}
mongo  | {"t":{"$date":"2025-09-20T16:28:41.693+00:00"},"s":"I",  "c":"CONTROL",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":1,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"b3654a9aa21e"}}
mongo  | {"t":{"$date":"2025-09-20T16:28:41.693+00:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"7.0.24","gitVersion":"332b0e6c30fdc41a0228dc55657e2e0784b0fe24","openSSLVersion":"OpenSSL 3.0.2 15 Mar 2022","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu2204","distarch":"x86_64","target_arch":"x86_64"}}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:41.693+00:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"22.04"}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:41.693+00:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"net":{"bindIp":"*"}}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:41.702+00:00"},"s":"I",  "c":"STORAGE",  "id":22315,   "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=3312M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,remove=true,path=journal,compressor=snappy),builtin_extension_config=(zstd=(compression_level=6)),file_manager=(close_idle_time=600,close_scan_interval=10,close_handle_minimum=2000),statistics_log=(wait=0),json_output=(error,message),verbose=[recovery_progress:1,checkpoint_progress:1,compact_progress:1,backup:0,checkpoint:0,compact:0,evict:0,history_store:0,recovery:0,rts:0,salvage:0,tiered:0,timestamp:0,transaction:0,verify:0,log:0],"}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.765+00:00"},"s":"I",  "c":"WTRECOV",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":{"ts_sec":1758385722,"ts_usec":765098,"thread":"1:0x7f8f84b91c80","session_name":"txn-recover","category":"WT_VERB_RECOVERY_PROGRESS","category_id":30,"verbose_level":"DEBUG_1","verbose_level_id":1,"msg":"recovery log replay has successfully finished and ran for 0 milliseconds"}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.765+00:00"},"s":"I",  "c":"WTRECOV",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":{"ts_sec":1758385722,"ts_usec":765335,"thread":"1:0x7f8f84b91c80","session_name":"txn-recover","category":"WT_VERB_RECOVERY_PROGRESS","category_id":30,"verbose_level":"DEBUG_1","verbose_level_id":1,"msg":"Set global recovery timestamp: (0, 0)"}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.765+00:00"},"s":"I",  "c":"WTRECOV",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":{"ts_sec":1758385722,"ts_usec":765399,"thread":"1:0x7f8f84b91c80","session_name":"txn-recover","category":"WT_VERB_RECOVERY_PROGRESS","category_id":30,"verbose_level":"DEBUG_1","verbose_level_id":1,"msg":"Set global oldest timestamp: (0, 0)"}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.765+00:00"},"s":"I",  "c":"WTRECOV",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":{"ts_sec":1758385722,"ts_usec":765479,"thread":"1:0x7f8f84b91c80","session_name":"txn-recover","category":"WT_VERB_RECOVERY_PROGRESS","category_id":30,"verbose_level":"DEBUG_1","verbose_level_id":1,"msg":"recovery was completed successfully and took 1ms, including 0ms for the log replay, 0ms for the rollback to stable, and 0ms for the checkpoint."}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.778+00:00"},"s":"I",  "c":"STORAGE",  "id":4795906, "ctx":"initandlisten","msg":"WiredTiger opened","attr":{"durationMillis":1076}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.778+00:00"},"s":"I",  "c":"RECOVERY", "id":23987,   "ctx":"initandlisten","msg":"WiredTiger recoveryTimestamp","attr":{"recoveryTimestamp":{"$timestamp":{"t":0,"i":0}}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.795+00:00"},"s":"W",  "c":"CONTROL",  "id":22120,   "ctx":"initandlisten","msg":"Access control is not enabled for the database. Read and write access to data and configuration is unrestricted","tags":["startupWarnings"]}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.796+00:00"},"s":"W",  "c":"CONTROL",  "id":9068900, "ctx":"initandlisten","msg":"For customers running MongoDB 7.0, we suggest changing the contents of the following sysfsFile","attr":{"sysfsFile":"/sys/kernel/mm/transparent_hugepage","currentValue":"always","desiredValue":"never"},"tags":["startupWarnings"]}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.796+00:00"},"s":"W",  "c":"CONTROL",  "id":5123300, "ctx":"initandlisten","msg":"vm.max_map_count is too low","attr":{"currentValue":65530,"recommendedMinimum":2000000,"maxConns":1000000},"tags":["startupWarnings"]}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.796+00:00"},"s":"I",  "c":"STORAGE",  "id":20320,   "ctx":"initandlisten","msg":"createCollection","attr":{"namespace":"admin.system.version","uuidDisposition":"provided","uuid":{"uuid":{"$uuid":"2008b2a4-a090-4bd5-891c-65eda11f58fd"}},"options":{"uuid":{"$uuid":"2008b2a4-a090-4bd5-891c-65eda11f58fd"}}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.838+00:00"},"s":"I",  "c":"INDEX",    "id":20345,   "ctx":"initandlisten","msg":"Index build: done building","attr":{"buildUUID":null,"collectionUUID":{"uuid":{"$uuid":"2008b2a4-a090-4bd5-891c-65eda11f58fd"}},"namespace":"admin.system.version","index":"_id_","ident":"index-1-1888943135463382814","collectionIdent":"collection-0-1888943135463382814","commitTimestamp":null}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.839+00:00"},"s":"I",  "c":"REPL",     "id":20459,   "ctx":"initandlisten","msg":"Setting featureCompatibilityVersion","attr":{"newVersion":"7.0"}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.839+00:00"},"s":"I",  "c":"REPL",     "id":5853300, "ctx":"initandlisten","msg":"current featureCompatibilityVersion value","attr":{"featureCompatibilityVersion":"7.0","context":"setFCV"}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.839+00:00"},"s":"I",  "c":"NETWORK",  "id":4915702, "ctx":"initandlisten","msg":"Updated wire specification","attr":{"oldSpec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":21},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":21},"outgoing":{"minWireVersion":6,"maxWireVersion":21},"isInternalClient":true},"newSpec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":21},"incomingInternalClient":{"minWireVersion":21,"maxWireVersion":21},"outgoing":{"minWireVersion":21,"maxWireVersion":21},"isInternalClient":true}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.839+00:00"},"s":"I",  "c":"NETWORK",  "id":4915702, "ctx":"initandlisten","msg":"Updated wire specification","attr":{"oldSpec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":21},"incomingInternalClient":{"minWireVersion":21,"maxWireVersion":21},"outgoing":{"minWireVersion":21,"maxWireVersion":21},"isInternalClient":true},"newSpec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":21},"incomingInternalClient":{"minWireVersion":21,"maxWireVersion":21},"outgoing":{"minWireVersion":21,"maxWireVersion":21},"isInternalClient":true}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.839+00:00"},"s":"I",  "c":"REPL",     "id":5853300, "ctx":"initandlisten","msg":"current featureCompatibilityVersion value","attr":{"featureCompatibilityVersion":"7.0","context":"startup"}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.839+00:00"},"s":"I",  "c":"STORAGE",  "id":5071100, "ctx":"initandlisten","msg":"Clearing temp directory"}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.839+00:00"},"s":"I",  "c":"CONTROL",  "id":6608200, "ctx":"initandlisten","msg":"Initializing cluster server parameters from disk"}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.840+00:00"},"s":"I",  "c":"CONTROL",  "id":20536,   "ctx":"initandlisten","msg":"Flow Control is enabled on this deployment"}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.841+00:00"},"s":"I",  "c":"FTDC",     "id":20625,   "ctx":"initandlisten","msg":"Initializing full-time diagnostic data capture","attr":{"dataDirectory":"/data/db/diagnostic.data"}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.845+00:00"},"s":"I",  "c":"STORAGE",  "id":20320,   "ctx":"initandlisten","msg":"createCollection","attr":{"namespace":"local.startup_log","uuidDisposition":"generated","uuid":{"uuid":{"$uuid":"5a751a1e-ebd2-42df-b96c-1a059e388839"}},"options":{"capped":true,"size":10485760}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.858+00:00"},"s":"I",  "c":"INDEX",    "id":20345,   "ctx":"initandlisten","msg":"Index build: done building","attr":{"buildUUID":null,"collectionUUID":{"uuid":{"$uuid":"5a751a1e-ebd2-42df-b96c-1a059e388839"}},"namespace":"local.startup_log","index":"_id_","ident":"index-3-1888943135463382814","collectionIdent":"collection-2-1888943135463382814","commitTimestamp":null}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.858+00:00"},"s":"I",  "c":"REPL",     "id":6015317, "ctx":"initandlisten","msg":"Setting new configuration state","attr":{"newState":"ConfigReplicationDisabled","oldState":"ConfigPreStart"}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.858+00:00"},"s":"I",  "c":"STORAGE",  "id":22262,   "ctx":"initandlisten","msg":"Timestamp monitor starting"}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.862+00:00"},"s":"I",  "c":"STORAGE",  "id":20320,   "ctx":"LogicalSessionCacheRefresh","msg":"createCollection","attr":{"namespace":"config.system.sessions","uuidDisposition":"generated","uuid":{"uuid":{"$uuid":"ae51aef7-160b-4a59-8611-f6567d8d3c87"}},"options":{}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.862+00:00"},"s":"I",  "c":"CONTROL",  "id":20712,   "ctx":"LogicalSessionCacheReap","msg":"Sessions collection is not set up; waiting until next sessions reap interval","attr":{"error":"NamespaceNotFound: config.system.sessions does not exist"}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.863+00:00"},"s":"I",  "c":"NETWORK",  "id":23015,   "ctx":"listener","msg":"Listening on","attr":{"address":"/tmp/mongodb-27017.sock"}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.863+00:00"},"s":"I",  "c":"NETWORK",  "id":23015,   "ctx":"listener","msg":"Listening on","attr":{"address":"0.0.0.0"}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.863+00:00"},"s":"I",  "c":"NETWORK",  "id":23016,   "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.863+00:00"},"s":"I",  "c":"CONTROL",  "id":8423403, "ctx":"initandlisten","msg":"mongod startup complete","attr":{"Summary of time elapsed":{"Startup from clean shutdown?":true,"Statistics":{"Transport layer setup":"0 ms","Run initial syncer crash recovery":"0 ms","Create storage engine lock file in the data directory":"0 ms","Get metadata describing storage engine":"0 ms","Create storage engine":"1088 ms","Write current PID to file":"0 ms","Write a new metadata for storage engine":"0 ms","Initialize FCV before rebuilding indexes":"0 ms","Drop abandoned idents and get back indexes that need to be rebuilt or builds that need to be restarted":"0 ms","Rebuild indexes for collections":"0 ms","Load cluster parameters from disk for a standalone":"0 ms","Build user and roles graph":"0 ms","Set up the background thread pool responsible for waiting for opTimes to be majority committed":"1 ms","Initialize information needed to make a mongod instance shard aware":"1 ms","Start up the replication coordinator":"0 ms","Start transport layer":"2 ms","_initAndListen total elapsed time":"1170 ms"}}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.876+00:00"},"s":"I",  "c":"REPL",     "id":7360102, "ctx":"LogicalSessionCacheRefresh","msg":"Added oplog entry for create to transaction","attr":{"namespace":"config.$cmd","uuid":{"uuid":{"$uuid":"ae51aef7-160b-4a59-8611-f6567d8d3c87"}},"object":{"create":"system.sessions","idIndex":{"v":2,"key":{"_id":1},"name":"_id_"}}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.877+00:00"},"s":"I",  "c":"REPL",     "id":7360100, "ctx":"LogicalSessionCacheRefresh","msg":"Added oplog entry for createIndexes to transaction","attr":{"namespace":"config.$cmd","uuid":{"uuid":{"$uuid":"ae51aef7-160b-4a59-8611-f6567d8d3c87"}},"object":{"createIndexes":"system.sessions","v":2,"key":{"lastUse":1},"name":"lsidTTLIndex","expireAfterSeconds":1800}}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.883+00:00"},"s":"I",  "c":"INDEX",    "id":20345,   "ctx":"LogicalSessionCacheRefresh","msg":"Index build: done building","attr":{"buildUUID":null,"collectionUUID":{"uuid":{"$uuid":"ae51aef7-160b-4a59-8611-f6567d8d3c87"}},"namespace":"config.system.sessions","index":"_id_","ident":"index-5-1888943135463382814","collectionIdent":"collection-4-1888943135463382814","commitTimestamp":null}}
mongo  | {"t":{"$date":"2025-09-20T16:28:42.883+00:00"},"s":"I",  "c":"INDEX",    "id":20345,   "ctx":"LogicalSessionCacheRefresh","msg":"Index build: done building","attr":{"buildUUID":null,"collectionUUID":{"uuid":{"$uuid":"ae51aef7-160b-4a59-8611-f6567d8d3c87"}},"namespace":"config.system.sessions","index":"lsidTTLIndex","ident":"index-6-1888943135463382814","collectionIdent":"collection-4-1888943135463382814","commitTimestamp":null}}
node-mongo  | (node:1) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
node-mongo  | (Use `node --trace-deprecation ...` to show where the warning was created)
node-mongo  | (node:1) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
node-mongo  | 服务器正在运行,端口:3000(访问地址:http://localhost:3000)

mongo       | {"t":{"$date":"2025-09-20T16:28:43.863+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.18.0.3:58210","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"b6dac08b-63c4-460d-b1e2-d3c6844c8df5"}},"connectionId":1,"connectionCount":1}}
mongo       | {"t":{"$date":"2025-09-20T16:28:43.892+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn1","msg":"client metadata","attr":{"remote":"172.18.0.3:58210","client":"conn1","negotiatedCompressors":[],"doc":{"driver":{"name":"nodejs","version":"3.7.4"},"os":{"type":"Linux","name":"linux","architecture":"x64","version":"5.14.0-611.el9.x86_64"},"platform":"'Node.js v18.0.0, LE (legacy)"}}}
node-mongo  | MongoDB 连接成功!

测试模板代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>事项管理</title>
</head>
<body>
    <h1>测试模板</h1>
    <%= 'Hello EJS' %>
</body>
</html>

注意:

全过程代码(前半段显示不出来):

node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
^C
dg
^C[root@host1 src]# 
[root@host1 src]# vi src/views/index.ejs
[root@host1 src]# cat src/views/index.ejs
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>测试模板</title>
</head>
<body>
    <h1>测试页面</h1>
    <!-- 仅保留最简单的 EJS 输出 -->
    <%= '模板渲染成功' %>
</body>
</html>
[root@host1 src]# docker compose down
docker compose up --build -d
docker compose logs -f app
WARN[0000] /root/nodejs-mongo/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Running 3/3
 ✔ Container node-mongo          Removed                                                       10.5s 
 ✔ Container mongo               Removed                                                        0.5s 
 ✔ Network nodejs-mongo_default  Removed                                                        0.3s 
WARN[0000] /root/nodejs-mongo/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Building 13.5s (13/13) FINISHED                                                                  
 => [internal] load local bake definitions                                                      0.0s
 => => reading from stdin 487B                                                                  0.0s
 => [internal] load build definition from Dockerfile                                            0.0s
 => => transferring dockerfile: 306B                                                            0.0s
 => [internal] load metadata for docker.io/library/node:18.0.0-alpine                           1.2s
 => [internal] load .dockerignore                                                               0.0s
 => => transferring context: 2B                                                                 0.0s
 => [1/6] FROM docker.io/library/node:18.0.0-alpine@sha256:469ee26d9e00547ea91202a34ff2542f984  0.0s
 => [internal] load build context                                                               5.3s
 => => transferring context: 314.94MB                                                           5.3s
 => CACHED [2/6] WORKDIR /usr/src/app                                                           0.0s
 => CACHED [3/6] COPY package*.json ./                                                          0.0s
 => CACHED [4/6] RUN npm config set registry https://registry.npmmirror.com                     0.0s
 => CACHED [5/6] RUN npm install --production                                                   0.0s
 => [6/6] COPY . .                                                                              5.3s
 => exporting to image                                                                          1.5s
 => => exporting layers                                                                         1.5s
 => => writing image sha256:905f65df8eb86c1523ffa7626d93bf6748742405c9304aabc38a1edcae514db1    0.0s
 => => naming to docker.io/library/nodejs-mongo-app                                             0.0s
 => resolving provenance for metadata file                                                      0.0s
[+] Running 4/4
 ✔ nodejs-mongo-app              Built                                                          0.0s 
 ✔ Network nodejs-mongo_default  Created                                                        0.2s 
 ✔ Container mongo               Started                                                        2.0s 
 ✔ Container node-mongo          Started                                                        2.7s 
WARN[0000] /root/nodejs-mongo/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
node-mongo  | (node:1) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
node-mongo  | (Use `node --trace-deprecation ...` to show where the warning was created)
node-mongo  | (node:1) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
node-mongo  | 服务器正在运行,端口:3000(访问地址:http://localhost:3000)
node-mongo  | MongoDB 连接成功!
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
dg
^C


dg
^C[root@host1 src]# 
[root@host1 src]# vim src/views/index.ejs
[root@host1 src]# cat src/views/index.ejs
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>测试模板</title>
</head>
<body>
    <h1>测试页面</h1>
    <!-- 仅保留最简单的 EJS 输出 -->
    <%= '模板渲染成功' %>
</body>
</html

:set fileencoding=utf-8
:set bomb! 
:%s/[^\x20-\x7E]//g  >
[root@host1 src]# docker compose down
WARN[0000] /root/nodejs-mongo/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Running 3/3
 ✔ Container node-mongo          Removed                                                       10.4s 
 ✔ Container mongo               Removed                                                        0.4s 
 ✔ Network nodejs-mongo_default  Removed                                                        0.2s 
[root@host1 src]# docker compose up --build -d
WARN[0000] /root/nodejs-mongo/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Building 17.5s (13/13) FINISHED                                                                  
 => [internal] load local bake definitions                                                      0.0s
 => => reading from stdin 487B                                                                  0.0s
 => [internal] load build definition from Dockerfile                                            0.0s
 => => transferring dockerfile: 306B                                                            0.0s
 => [internal] load metadata for docker.io/library/node:18.0.0-alpine                           7.0s
 => [internal] load .dockerignore                                                               0.0s
 => => transferring context: 2B                                                                 0.0s
 => [1/6] FROM docker.io/library/node:18.0.0-alpine@sha256:469ee26d9e00547ea91202a34ff2542f984  0.0s
 => [internal] load build context                                                               4.6s
 => => transferring context: 314.93MB                                                           4.5s
 => CACHED [2/6] WORKDIR /usr/src/app                                                           0.0s
 => CACHED [3/6] COPY package*.json ./                                                          0.0s
 => CACHED [4/6] RUN npm config set registry https://registry.npmmirror.com                     0.0s
 => CACHED [5/6] RUN npm install --production                                                   0.0s
 => [6/6] COPY . .                                                                              4.2s
 => exporting to image                                                                          1.3s
 => => exporting layers                                                                         1.2s
 => => writing image sha256:90ef64208e6ecee5db96ad27be5936a07b220d0a0d6dc82f317c3007f0636ffe    0.0s
 => => naming to docker.io/library/nodejs-mongo-app                                             0.0s
 => resolving provenance for metadata file                                                      0.0s
[+] Running 4/4
 ✔ nodejs-mongo-app              Built                                                          0.0s 
 ✔ Network nodejs-mongo_default  Created                                                        0.1s 
 ✔ Container mongo               Started                                                        2.5s 
 ✔ Container node-mongo          Started                                                        3.3s 
[root@host1 src]# vim src/views/index.ejs
[root@host1 src]# cat src/views/index.ejs

:set fileencoding=utf-8
:set bomb! 
:%s/[^\x20-\x7E]//g  

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>测试模板</title>
</head>
<body>
    <h1>事项管理系统</h1>
    <!-- 静态表单 -->
    <form method="post" action="/item/add">
        <label for="name">事项内容:</label>
        <input type="text" id="name" name="name">
        <input type="submit" value="添加">
    </form>
    <%= '模板渲染成功' %>
</body>
</html>>
[root@host1 src]# docker compose down
WARN[0000] /root/nodejs-mongo/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Running 3/3
 ✔ Container node-mongo          Removed                                                       10.7s 
 ✔ Container mongo               Removed                                                        0.5s 
 ✔ Network nodejs-mongo_default  Removed                                                        0.2s 
[root@host1 src]# docker compose up --build -d
WARN[0000] /root/nodejs-mongo/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Building 12.4s (13/13) FINISHED                                                                  
 => [internal] load local bake definitions                                                      0.0s
 => => reading from stdin 487B                                                                  0.0s
 => [internal] load build definition from Dockerfile                                            0.0s
 => => transferring dockerfile: 306B                                                            0.0s
 => [internal] load metadata for docker.io/library/node:18.0.0-alpine                           1.1s
 => [internal] load .dockerignore                                                               0.0s
 => => transferring context: 2B                                                                 0.0s
 => [1/6] FROM docker.io/library/node:18.0.0-alpine@sha256:469ee26d9e00547ea91202a34ff2542f984  0.0s
 => [internal] load build context                                                               4.6s
 => => transferring context: 314.95MB                                                           4.6s
 => CACHED [2/6] WORKDIR /usr/src/app                                                           0.0s
 => CACHED [3/6] COPY package*.json ./                                                          0.0s
 => CACHED [4/6] RUN npm config set registry https://registry.npmmirror.com                     0.0s
 => CACHED [5/6] RUN npm install --production                                                   0.0s
 => [6/6] COPY . .                                                                              4.9s
 => exporting to image                                                                          1.3s
 => => exporting layers                                                                         1.2s
 => => writing image sha256:f261808fde547fffc1e9b34902d6d1c48a1d9e83c0f05edc216a84bdac0c286f    0.0s
 => => naming to docker.io/library/nodejs-mongo-app                                             0.0s
 => resolving provenance for metadata file                                                      0.0s
[+] Running 4/4
 ✔ nodejs-mongo-app              Built                                                          0.0s 
 ✔ Network nodejs-mongo_default  Created                                                        0.1s 
 ✔ Container mongo               Started                                                        2.1s 
 ✔ Container node-mongo          Started                                                        3.1s 
[root@host1 src]# vim src/views/index.ejs
[root@host1 src]# cat src/views/index.ejs
:set fileencoding=utf-8
:set bomb! 
:%s/[^\x20-\x7E]//g  

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Node.js 事项管理</title>
    <style>
        body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
        form { margin: 20px 0; }
        input[type="text"] { padding: 8px; width: 300px; }
        input[type="submit"] { padding: 8px 20px; background: #007bff; color: white; border: none; cursor: pointer; }
        ul { list-style: none; padding: 0; }
        li { padding: 10px; border-bottom: 1px solid #eee; }
        .empty { color: #666; }
    </style>
</head>
<body>
    <h1>事项管理系统</h1>

    <!-- 添加事项表单 -->
    <form method="post" action="/item/add">
        <label for="name">事项内容:</label>
        <input type="text" id="name" name="name" required>
        <input type="submit" value="添加">
    </form>

    <!-- 事项列表(EJS 渲染部分) -->
    <h3>当前事项:</h3>
    <ul>
        <% if (items && items.length > 0) { %>
            <% items.forEach(function(item) { %>
                <li>
                    <%= item.name %>
                    <small style="color: #999; margin-left: 10px;">
                        <%= new Date(item.createdAt).toLocaleString() %>
                    </small>
                </li>
            <% }) %>
        <% } else { %>
            <li class="empty">暂无事项,请添加新内容~</li>
        <% } %>
    </ul>
</body>
</html>

[root@host1 src]# cd
[root@host1 ~]# cd /root/nodejs-mongo
[root@host1 nodejs-mongo]# docker compose up --build
WARN[0000] /root/nodejs-mongo/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Building 10.3s (13/13) FINISHED                                                                  
 => [internal] load local bake definitions                                                      0.0s
 => => reading from stdin 487B                                                                  0.0s
 => [internal] load build definition from Dockerfile                                            0.0s
 => => transferring dockerfile: 306B                                                            0.0s
 => [internal] load metadata for docker.io/library/node:18.0.0-alpine                           1.1s
 => [internal] load .dockerignore                                                               0.0s
 => => transferring context: 2B                                                                 0.0s
 => [1/6] FROM docker.io/library/node:18.0.0-alpine@sha256:469ee26d9e00547ea91202a34ff2542f984  0.0s
 => [internal] load build context                                                               4.6s
 => => transferring context: 314.95MB                                                           4.6s
 => CACHED [2/6] WORKDIR /usr/src/app                                                           0.0s
 => CACHED [3/6] COPY package*.json ./                                                          0.0s
 => CACHED [4/6] RUN npm config set registry https://registry.npmmirror.com                     0.0s
 => CACHED [5/6] RUN npm install --production                                                   0.0s
 => [6/6] COPY . .                                                                              2.7s
 => exporting to image                                                                          1.3s
 => => exporting layers                                                                         1.3s
 => => writing image sha256:3f1a2127381e8b557afa6f5393eca4b05c3e8f2d343783d9d781b6aabbbdb403    0.0s
 => => naming to docker.io/library/nodejs-mongo-app                                             0.0s
 => resolving provenance for metadata file                                                      0.0s
[+] Running 3/3
 ✔ nodejs-mongo-app      Built                                                                  0.0s 
 ✔ Container mongo       Running                                                                0.0s 
 ✔ Container node-mongo  Recreated                                                             10.7s 
Attaching to mongo, node-mongo
node-mongo  | (node:1) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
node-mongo  | (Use `node --trace-deprecation ...` to show where the warning was created)
node-mongo  | (node:1) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
node-mongo  | 服务器正在运行,端口:3000(访问地址:http://localhost:3000)
mongo       | {"t":{"$date":"2025-09-20T16:58:46.210+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.18.0.3:37860","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"7712bcc3-d46a-4e68-b0c2-a17cd059b708"}},"connectionId":2,"connectionCount":1}}
mongo       | {"t":{"$date":"2025-09-20T16:58:46.237+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn2","msg":"client metadata","attr":{"remote":"172.18.0.3:37860","client":"conn2","negotiatedCompressors":[],"doc":{"driver":{"name":"nodejs","version":"3.7.4"},"os":{"type":"Linux","name":"linux","architecture":"x64","version":"5.14.0-611.el9.x86_64"},"platform":"'Node.js v18.0.0, LE (legacy)"}}}
node-mongo  | MongoDB 连接成功!
mongo       | {"t":{"$date":"2025-09-20T16:58:50.138+00:00"},"s":"I",  "c":"NETWORK",  "id":6788700, "ctx":"conn2","msg":"Received first command on ingress connection since session start or auth handshake","attr":{"elapsedMillis":3900}}
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
node-mongo  | SyntaxError: Invalid or unexpected token in /usr/src/app/src/views/index.ejs while compiling ejs
node-mongo  | 
node-mongo  | If the above error is not helpful, you may want to try EJS-Lint:
node-mongo  | https://github.com/RyanZim/EJS-Lint
node-mongo  | Or, if you meant to create an async function, pass `async: true` as an option.
node-mongo  |     at new Function (<anonymous>)
node-mongo  |     at Template.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:673:12)
node-mongo  |     at Object.compile (/usr/src/app/node_modules/ejs/lib/ejs.js:398:16)
node-mongo  |     at handleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:235:18)
node-mongo  |     at tryHandleCache (/usr/src/app/node_modules/ejs/lib/ejs.js:274:16)
node-mongo  |     at exports.renderFile [as engine] (/usr/src/app/node_modules/ejs/lib/ejs.js:491:10)
node-mongo  |     at View.render (/usr/src/app/node_modules/express/lib/view.js:135:8)
node-mongo  |     at tryRender (/usr/src/app/node_modules/express/lib/application.js:657:10)
node-mongo  |     at Function.render (/usr/src/app/node_modules/express/lib/application.js:609:3)
node-mongo  |     at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1049:7)
node-mongo  |     at /usr/src/app/src/index.js:20:11
node-mongo  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
mongo       | {"t":{"$date":"2025-09-20T16:59:27.186+00:00"},"s":"I",  "c":"WTCHKPT",  "id":22430,   "ctx":"Checkpointer","msg":"WiredTiger message","attr":{"message":{"ts_sec":1758387567,"ts_usec":186134,"thread":"1:0x7f4eedf06640","session_name":"WT_SESSION.checkpoint","category":"WT_VERB_CHECKPOINT_PROGRESS","category_id":6,"verbose_level":"DEBUG_1","verbose_level_id":1,"msg":"saving checkpoint snapshot min: 6, snapshot max: 6 snapshot count: 0, oldest timestamp: (0, 0) , meta checkpoint timestamp: (0, 0) base write gen: 78"}}}
mongo       | {"t":{"$date":"2025-09-20T17:00:27.222+00:00"},"s":"I",  "c":"WTCHKPT",  "id":22430,   "ctx":"Checkpointer","msg":"WiredTiger message","attr":{"message":{"ts_sec":1758387627,"ts_usec":222081,"thread":"1:0x7f4eedf06640","session_name":"WT_SESSION.checkpoint","category":"WT_VERB_CHECKPOINT_PROGRESS","category_id":6,"verbose_level":"DEBUG_1","verbose_level_id":1,"msg":"saving checkpoint snapshot min: 7, snapshot max: 7 snapshot count: 0, oldest timestamp: (0, 0) , meta checkpoint timestamp: (0, 0) base write gen: 78"}}}
Gracefully Stopping... press Ctrl+C again to force
 Container node-mongo  Stopping
mongo       | {"t":{"$date":"2025-09-20T17:00:41.074+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn2","msg":"Connection ended","attr":{"remote":"172.18.0.3:37860","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"7712bcc3-d46a-4e68-b0c2-a17cd059b708"}},"connectionId":2,"connectionCount":0}}
 Container node-mongo  Stopped
 Container mongo  Stopping
node-mongo exited with code 137
mongo       | {"t":{"$date":"2025-09-20T17:00:41.369+00:00"},"s":"I",  "c":"CONTROL",  "id":23377,   "ctx":"SignalHandler","msg":"Received signal","attr":{"signal":15,"error":"Terminated"}}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.370+00:00"},"s":"I",  "c":"CONTROL",  "id":23378,   "ctx":"SignalHandler","msg":"Signal was sent by kill(2)","attr":{"pid":0,"uid":0}}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.370+00:00"},"s":"I",  "c":"CONTROL",  "id":23381,   "ctx":"SignalHandler","msg":"will terminate after current cmd ends"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.370+00:00"},"s":"I",  "c":"REPL",     "id":4784900, "ctx":"SignalHandler","msg":"Stepping down the ReplicationCoordinator for shutdown","attr":{"waitTimeMillis":15000}}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.370+00:00"},"s":"I",  "c":"REPL",     "id":4794602, "ctx":"SignalHandler","msg":"Attempting to enter quiesce mode"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.371+00:00"},"s":"I",  "c":"-",        "id":6371601, "ctx":"SignalHandler","msg":"Shutting down the FLE Crud thread pool"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.371+00:00"},"s":"I",  "c":"COMMAND",  "id":4784901, "ctx":"SignalHandler","msg":"Shutting down the MirrorMaestro"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.371+00:00"},"s":"I",  "c":"SHARDING", "id":4784902, "ctx":"SignalHandler","msg":"Shutting down the WaitForMajorityService"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.374+00:00"},"s":"I",  "c":"CONTROL",  "id":4784903, "ctx":"SignalHandler","msg":"Shutting down the LogicalSessionCache"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.375+00:00"},"s":"I",  "c":"NETWORK",  "id":20562,   "ctx":"SignalHandler","msg":"Shutdown: going to close listening sockets"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.376+00:00"},"s":"I",  "c":"NETWORK",  "id":23017,   "ctx":"listener","msg":"removing socket file","attr":{"path":"/tmp/mongodb-27017.sock"}}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.376+00:00"},"s":"I",  "c":"NETWORK",  "id":4784905, "ctx":"SignalHandler","msg":"Shutting down the global connection pool"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.376+00:00"},"s":"I",  "c":"CONTROL",  "id":4784906, "ctx":"SignalHandler","msg":"Shutting down the FlowControlTicketholder"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.376+00:00"},"s":"I",  "c":"-",        "id":20520,   "ctx":"SignalHandler","msg":"Stopping further Flow Control ticket acquisitions."}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.376+00:00"},"s":"I",  "c":"CONTROL",  "id":4784908, "ctx":"SignalHandler","msg":"Shutting down the PeriodicThreadToAbortExpiredTransactions"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.377+00:00"},"s":"I",  "c":"REPL",     "id":4784909, "ctx":"SignalHandler","msg":"Shutting down the ReplicationCoordinator"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.377+00:00"},"s":"I",  "c":"SHARDING", "id":4784910, "ctx":"SignalHandler","msg":"Shutting down the ShardingInitializationMongoD"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.377+00:00"},"s":"I",  "c":"REPL",     "id":4784911, "ctx":"SignalHandler","msg":"Enqueuing the ReplicationStateTransitionLock for shutdown"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.377+00:00"},"s":"I",  "c":"-",        "id":4784912, "ctx":"SignalHandler","msg":"Killing all operations for shutdown"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.377+00:00"},"s":"I",  "c":"-",        "id":4695300, "ctx":"SignalHandler","msg":"Interrupted all currently running operations","attr":{"opsKilled":3}}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.377+00:00"},"s":"I",  "c":"TENANT_M", "id":5093807, "ctx":"SignalHandler","msg":"Shutting down all TenantMigrationAccessBlockers on global shutdown"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.377+00:00"},"s":"I",  "c":"ASIO",     "id":22582,   "ctx":"TenantMigrationBlockerNet","msg":"Killing all outstanding egress activity."}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.377+00:00"},"s":"I",  "c":"ASIO",     "id":6529201, "ctx":"SignalHandler","msg":"Network interface redundant shutdown","attr":{"state":"Stopped"}}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.377+00:00"},"s":"I",  "c":"ASIO",     "id":22582,   "ctx":"SignalHandler","msg":"Killing all outstanding egress activity."}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.377+00:00"},"s":"I",  "c":"COMMAND",  "id":4784913, "ctx":"SignalHandler","msg":"Shutting down all open transactions"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.377+00:00"},"s":"I",  "c":"REPL",     "id":4784914, "ctx":"SignalHandler","msg":"Acquiring the ReplicationStateTransitionLock for shutdown"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.377+00:00"},"s":"I",  "c":"INDEX",    "id":4784915, "ctx":"SignalHandler","msg":"Shutting down the IndexBuildsCoordinator"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.378+00:00"},"s":"I",  "c":"NETWORK",  "id":4784918, "ctx":"SignalHandler","msg":"Shutting down the ReplicaSetMonitor"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.378+00:00"},"s":"I",  "c":"SHARDING", "id":4784921, "ctx":"SignalHandler","msg":"Shutting down the MigrationUtilExecutor"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.378+00:00"},"s":"I",  "c":"ASIO",     "id":22582,   "ctx":"MigrationUtil-TaskExecutor","msg":"Killing all outstanding egress activity."}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.378+00:00"},"s":"I",  "c":"COMMAND",  "id":4784923, "ctx":"SignalHandler","msg":"Shutting down the ServiceEntryPoint"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.378+00:00"},"s":"I",  "c":"CONTROL",  "id":4784927, "ctx":"SignalHandler","msg":"Shutting down the HealthLog"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.378+00:00"},"s":"I",  "c":"CONTROL",  "id":4784928, "ctx":"SignalHandler","msg":"Shutting down the TTL monitor"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.378+00:00"},"s":"I",  "c":"INDEX",    "id":3684100, "ctx":"SignalHandler","msg":"Shutting down TTL collection monitor thread"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.382+00:00"},"s":"I",  "c":"INDEX",    "id":3684101, "ctx":"SignalHandler","msg":"Finished shutting down TTL collection monitor thread"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.382+00:00"},"s":"I",  "c":"CONTROL",  "id":6278511, "ctx":"SignalHandler","msg":"Shutting down the Change Stream Expired Pre-images Remover"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.382+00:00"},"s":"I",  "c":"CONTROL",  "id":4784929, "ctx":"SignalHandler","msg":"Acquiring the global lock for shutdown"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.382+00:00"},"s":"I",  "c":"CONTROL",  "id":4784930, "ctx":"SignalHandler","msg":"Shutting down the storage engine"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.382+00:00"},"s":"I",  "c":"STORAGE",  "id":22320,   "ctx":"SignalHandler","msg":"Shutting down journal flusher thread"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.383+00:00"},"s":"I",  "c":"STORAGE",  "id":22321,   "ctx":"SignalHandler","msg":"Finished shutting down journal flusher thread"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.383+00:00"},"s":"I",  "c":"STORAGE",  "id":22322,   "ctx":"SignalHandler","msg":"Shutting down checkpoint thread"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.383+00:00"},"s":"I",  "c":"STORAGE",  "id":22323,   "ctx":"SignalHandler","msg":"Finished shutting down checkpoint thread"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.383+00:00"},"s":"I",  "c":"STORAGE",  "id":22261,   "ctx":"SignalHandler","msg":"Timestamp monitor shutting down"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.384+00:00"},"s":"I",  "c":"STORAGE",  "id":20282,   "ctx":"SignalHandler","msg":"Deregistering all the collections"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.384+00:00"},"s":"I",  "c":"STORAGE",  "id":22317,   "ctx":"SignalHandler","msg":"WiredTigerKVEngine shutting down"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.384+00:00"},"s":"I",  "c":"STORAGE",  "id":22318,   "ctx":"SignalHandler","msg":"Shutting down session sweeper thread"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.384+00:00"},"s":"I",  "c":"STORAGE",  "id":22319,   "ctx":"SignalHandler","msg":"Finished shutting down session sweeper thread"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.385+00:00"},"s":"I",  "c":"STORAGE",  "id":4795902, "ctx":"SignalHandler","msg":"Closing WiredTiger","attr":{"closeConfig":"leak_memory=true,use_timestamp=false,"}}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.385+00:00"},"s":"I",  "c":"WTCHKPT",  "id":22430,   "ctx":"SignalHandler","msg":"WiredTiger message","attr":{"message":{"ts_sec":1758387641,"ts_usec":385495,"thread":"1:0x7f4ef6f18640","session_name":"close_ckpt","category":"WT_VERB_CHECKPOINT_PROGRESS","category_id":6,"verbose_level":"DEBUG_1","verbose_level_id":1,"msg":"saving checkpoint snapshot min: 8, snapshot max: 8 snapshot count: 0, oldest timestamp: (0, 0) , meta checkpoint timestamp: (0, 0) base write gen: 78"}}}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.391+00:00"},"s":"I",  "c":"WTRECOV",  "id":22430,   "ctx":"SignalHandler","msg":"WiredTiger message","attr":{"message":{"ts_sec":1758387641,"ts_usec":391799,"thread":"1:0x7f4ef6f18640","session_name":"WT_CONNECTION.close","category":"WT_VERB_RECOVERY_PROGRESS","category_id":30,"verbose_level":"DEBUG_1","verbose_level_id":1,"msg":"shutdown checkpoint has successfully finished and ran for 6 milliseconds"}}}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.392+00:00"},"s":"I",  "c":"WTRECOV",  "id":22430,   "ctx":"SignalHandler","msg":"WiredTiger message","attr":{"message":{"ts_sec":1758387641,"ts_usec":392194,"thread":"1:0x7f4ef6f18640","session_name":"WT_CONNECTION.close","category":"WT_VERB_RECOVERY_PROGRESS","category_id":30,"verbose_level":"DEBUG_1","verbose_level_id":1,"msg":"shutdown was completed successfully and took 7ms, including 0ms for the rollback to stable, and 6ms for the checkpoint."}}}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.400+00:00"},"s":"I",  "c":"STORAGE",  "id":4795901, "ctx":"SignalHandler","msg":"WiredTiger closed","attr":{"durationMillis":15}}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.400+00:00"},"s":"I",  "c":"STORAGE",  "id":22279,   "ctx":"SignalHandler","msg":"shutdown: removing fs lock..."}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.400+00:00"},"s":"I",  "c":"-",        "id":4784931, "ctx":"SignalHandler","msg":"Dropping the scope cache for shutdown"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.400+00:00"},"s":"I",  "c":"FTDC",     "id":20626,   "ctx":"SignalHandler","msg":"Shutting down full-time diagnostic data capture"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.416+00:00"},"s":"I",  "c":"CONTROL",  "id":20565,   "ctx":"SignalHandler","msg":"Now exiting"}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.416+00:00"},"s":"I",  "c":"CONTROL",  "id":8423404, "ctx":"SignalHandler","msg":"mongod shutdown complete","attr":{"Summary of time elapsed":{"Statistics":{"Enter terminal shutdown":"0 ms","Step down the replication coordinator for shutdown":"0 ms","Time spent in quiesce mode":"0 ms","Shut down FLE Crud subsystem":"1 ms","Shut down MirrorMaestro":"0 ms","Shut down WaitForMajorityService":"1 ms","Shut down the logical session cache":"2 ms","Shut down the transport layer":"2 ms","Shut down the global connection pool":"0 ms","Shut down the flow control ticket holder":"0 ms","Kill all operations for shutdown":"0 ms","Shut down all tenant migration access blockers on global shutdown":"0 ms","Shut down all open transactions":"0 ms","Acquire the RSTL for shutdown":"0 ms","Shut down the IndexBuildsCoordinator and wait for index builds to finish":"0 ms","Shut down the replica set monitor":"1 ms","Shut down the migration util executor":"0 ms","Shut down the health log":"0 ms","Shut down the TTL monitor":"4 ms","Shut down expired pre-images and documents removers":"0 ms","Shut down the storage engine":"18 ms","Wait for the oplog cap maintainer thread to stop":"0 ms","Shut down full-time data capture":"10 ms","shutdownTask total elapsed time":"46 ms"}}}}
mongo       | {"t":{"$date":"2025-09-20T17:00:41.416+00:00"},"s":"I",  "c":"CONTROL",  "id":23138,   "ctx":"SignalHandler","msg":"Shutting down","attr":{"exitCode":0}}
 Container mongo  Stopped
[root@host1 nodejs-mongo]# cd /root/nodejs-mongo/src/views
[root@host1 views]# rm -f index.ejs
[root@host1 views]# touch index.ejs
[root@host1 views]# vim index.ejs
[root@host1 views]# cat index.ejs
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>事项管理</title>
</head>
<body>
    <h1>测试模板</h1>
    <%= 'Hello EJS' %>
</body>
</html>
[root@host1 views]# cd /root/nodejs-mongo
[root@host1 nodejs-mongo]# npm install ejs-lint --save-dev

added 180 packages, and audited 181 packages in 52s

27 packages are looking for funding
  run `npm fund` for details

1 critical severity vulnerability

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.
[root@host1 nodejs-mongo]# npm audit
# npm audit report

mongoose  <=6.13.5
Severity: critical
Mongoose search injection vulnerability - https://github.com/advisories/GHSA-m7xq-9374-9rvx
Mongoose search injection vulnerability - https://github.com/advisories/GHSA-vg7j-7cwx-8wgw
fix available via `npm audit fix --force`
Will install mongoose@8.18.1, which is a breaking change
node_modules/mongoose

1 critical severity vulnerability

To address all issues (including breaking changes), run:
  npm audit fix --force
[root@host1 nodejs-mongo]# npm audit fix

up to date, audited 181 packages in 7s

27 packages are looking for funding
  run `npm fund` for details

# npm audit report

mongoose  <=6.13.5
Severity: critical
Mongoose search injection vulnerability - https://github.com/advisories/GHSA-m7xq-9374-9rvx
Mongoose search injection vulnerability - https://github.com/advisories/GHSA-vg7j-7cwx-8wgw
fix available via `npm audit fix --force`
Will install mongoose@8.18.1, which is a breaking change
node_modules/mongoose

1 critical severity vulnerability

To address all issues (including breaking changes), run:
  npm audit fix --force
[root@host1 nodejs-mongo]# npm audit fix --force
npm WARN using --force Recommended protections disabled.
npm WARN audit Updating mongoose to 8.18.1, which is a SemVer major change.

added 9 packages, removed 23 packages, changed 9 packages, and audited 167 packages in 19s

27 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
[root@host1 nodejs-mongo]# grep "mongoose" package.json
    "mongoose": "^8.18.1"
[root@host1 nodejs-mongo]# docker compose down
WARN[0000] /root/nodejs-mongo/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Running 3/3
 ✔ Container node-mongo          Removed                                                        0.0s 
 ✔ Container mongo               Removed                                                        0.0s 
 ✔ Network nodejs-mongo_default  Removed                                                        0.2s 
[root@host1 nodejs-mongo]# docker compose up --build -d
WARN[0000] /root/nodejs-mongo/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Building 22.9s (13/13) FINISHED                                                                  
 => [internal] load local bake definitions                                                      0.0s
 => => reading from stdin 487B                                                                  0.0s
 => [internal] load build definition from Dockerfile                                            0.0s
 => => transferring dockerfile: 306B                                                            0.0s
 => [internal] load metadata for docker.io/library/node:18.0.0-alpine                           1.1s
 => [internal] load .dockerignore                                                               0.0s
 => => transferring context: 2B                                                                 0.0s
 => [1/6] FROM docker.io/library/node:18.0.0-alpine@sha256:469ee26d9e00547ea91202a34ff2542f984  0.0s
 => [internal] load build context                                                               2.4s
 => => transferring context: 123.52MB                                                           2.3s
 => CACHED [2/6] WORKDIR /usr/src/app                                                           0.0s
 => [3/6] COPY package*.json ./                                                                 0.5s
 => [4/6] RUN npm config set registry https://registry.npmmirror.com                            3.2s
 => [5/6] RUN npm install --production                                                         11.9s
 => [6/6] COPY . .                                                                              1.9s 
 => exporting to image                                                                          1.7s 
 => => exporting layers                                                                         1.6s 
 => => writing image sha256:a752bf36eeb17295d7bc12b2a834e56a98db6d459a95aa401c932dbb450373cd    0.0s 
 => => naming to docker.io/library/nodejs-mongo-app                                             0.0s 
 => resolving provenance for metadata file                                                      0.0s 
[+] Running 4/4
 ✔ nodejs-mongo-app              Built                                                          0.0s 
 ✔ Network nodejs-mongo_default  Created                                                        0.2s 
 ✔ Container mongo               Started                                                        0.8s 
 ✔ Container node-mongo          Started                                                        1.4s 
[root@host1 nodejs-mongo]# docker compose logs -f app
WARN[0000] /root/nodejs-mongo/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
node-mongo  | 服务器正在运行,端口:3000(访问地址:http://localhost:3000)
node-mongo  | MongoDB 连接成功!
^C
dg^C[root@host1 nodejs-mongo]# 
[root@host1 nodejs-mongo]# cd /root/nodejs-mongo/src/views
[root@host1 views]# vi index.ejs
[root@host1 views]# cat index.ejs
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Node.js 事项管理</title>
    <style>
        body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
        form { margin: 20px 0; }
        input[type="text"] { padding: 8px; width: 300px; }
        input[type="submit"] { padding: 8px 20px; background: #007bff; color: white; border: none; cursor: pointer; }
        ul { list-style: none; padding: 0; }
        li { padding: 10px; border-bottom: 1px solid #eee; }
        .empty { color: #666; }
    </style>
</head>
<body>
    <h1>事项管理系统</h1>

    <!-- 添加事项表单 -->
    <form method="post" action="/item/add">
        <label for="name">事项内容:</label>
        <input type="text" id="name" name="name" required>
        <input type="submit" value="添加">
    </form>

    <!-- 事项列表(EJS 渲染部分) -->
    <h3>当前事项:</h3>
    <ul>
        <% if (items && items.length > 0) { %>
            <% items.forEach(function(item) { %>
                <li>
                    <%= item.name %>
                    <small style="color: #999; margin-left: 10px;">
                        <%= new Date(item.createdAt).toLocaleString() %>
                    </small>
                </li>
            <% }) %>
        <% } else { %>
            <li class="empty">暂无事项,请添加新内容~</li>
        <% } %>
    </ul>
</body>
</html>
[root@host1 views]# yum install dos2unix -y
上次元数据过期检查:0:57:40 前,执行于 2025年09月21日 星期日 00时16分12秒。
软件包 dos2unix-7.4.2-4.el9.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!
[root@host1 views]# dos2unix src/views/index.ejs
dos2unix: src/views/index.ejs: 没有那个文件或目录
dos2unix: 跳过 src/views/index.ejs,不是一个普通文件。
[root@host1 views]# dos2unix index.ejs
dos2unix: 正在转换文件 index.ejs 为Unix格式...
[root@host1 views]# cd /root/nodejs-mongo
[root@host1 nodejs-mongo]# docker compose down
WARN[0000] /root/nodejs-mongo/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Running 3/3
 ✔ Container node-mongo          Removed                                                       10.4s 
 ✔ Container mongo               Removed                                                        0.5s 
 ✔ Network nodejs-mongo_default  Removed                                                        0.3s 
[root@host1 nodejs-mongo]# docker compose up --build -d
WARN[0000] /root/nodejs-mongo/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Building 19.5s (13/13) FINISHED                                                                  
 => [internal] load local bake definitions                                                      0.0s
 => => reading from stdin 487B                                                                  0.0s
 => [internal] load build definition from Dockerfile                                            0.0s
 => => transferring dockerfile: 306B                                                            0.0s
 => [internal] load metadata for docker.io/library/node:18.0.0-alpine                           2.3s
 => [internal] load .dockerignore                                                               0.0s
 => => transferring context: 2B                                                                 0.0s
 => [1/6] FROM docker.io/library/node:18.0.0-alpine@sha256:469ee26d9e00547ea91202a34ff2542f984  0.0s
 => [internal] load build context                                                               6.1s
 => => transferring context: 315.48MB                                                           6.1s
 => CACHED [2/6] WORKDIR /usr/src/app                                                           0.0s
 => CACHED [3/6] COPY package*.json ./                                                          0.0s
 => CACHED [4/6] RUN npm config set registry https://registry.npmmirror.com                     0.0s
 => CACHED [5/6] RUN npm install --production                                                   0.0s
 => [6/6] COPY . .                                                                              8.0s
 => exporting to image                                                                          2.6s
 => => exporting layers                                                                         2.6s
 => => writing image sha256:0baef989ea6849546e624013a5c4f11ad161ad97aa3ec4f57db8661f9cccc905    0.0s
 => => naming to docker.io/library/nodejs-mongo-app                                             0.0s
 => resolving provenance for metadata file                                                      0.0s
[+] Running 4/4
 ✔ nodejs-mongo-app              Built                                                          0.0s 
 ✔ Network nodejs-mongo_default  Created                                                        0.2s 
 ✔ Container mongo               Started                                                        0.7s 
 ✔ Container node-mongo          Started                                                        1.3s 
[root@host1 nodejs-mongo]# docker compose logs -f app
WARN[0000] /root/nodejs-mongo/compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
node-mongo  | 服务器正在运行,端口:3000(访问地址:http://localhost:3000)
node-mongo  | MongoDB 连接成功!
^C
dg^X
^Z
[1]+  已停止               docker compose logs -f app
[root@host1 nodejs-mongo]# 

Logo

码道开发者社区,聚焦华为云码道 CodeArts 代码智能体,沉淀 Agent、Skill、鸿蒙开发实战内容,供开发者查阅资料、交流技术、分享工程实践

更多推荐