【node.js】安裝與配置

在這里插入圖片描述

個人主頁:Guiat
歸屬專欄:node.js

在這里插入圖片描述

文章目錄

  • 1. Node.js簡介
    • 1.1 Node.js的特點
    • 1.2 Node.js架構
  • 2. Node.js安裝
    • 2.1 下載和安裝方法
      • 2.1.1 Windows安裝
      • 2.1.2 macOS安裝
      • 2.1.3 Linux安裝
    • 2.2 使用NVM安裝和管理Node.js版本
      • 2.2.1 安裝NVM
      • 2.2.2 使用NVM管理Node.js
    • 2.3 驗證安裝
  • 3. Node.js環境配置
    • 3.1 npm配置
      • 3.1.1 基礎npm配置
      • 3.1.2 創建.npmrc文件
    • 3.2 package.json配置
      • 3.2.1 創建package.json
      • 3.2.2 package.json示例
    • 3.3 環境變量配置
      • 3.3.1 使用dotenv管理環境變量
      • 3.3.2 不同環境的配置
    • 3.4 調試配置
      • 3.4.1 使用內置調試器
      • 3.4.2 VS Code調試配置
  • 4. 包管理工具
    • 4.1 npm基礎操作
    • 4.2 npm腳本配置
    • 4.3 yarn
      • 4.3.1 安裝yarn
      • 4.3.2 yarn基礎命令
    • 4.4 pnpm
      • 4.4.1 安裝pnpm
      • 4.4.2 pnpm基礎命令
      • 4.4.3 包管理器性能比較
  • 5. Node.js項目結構最佳實踐
    • 5.1 標準項目結構
    • 5.2 模塊化開發實踐
      • 5.2.1 控制器示例
      • 5.2.2 路由示例
      • 5.2.3 應用入口示例
    • 5.3 配置文件管理
  • 6. Node.js應用部署
    • 6.1 基本部署流程
    • 6.2 使用進程管理工具
      • 6.2.1 PM2
      • 6.2.2 PM2配置文件
    • 6.3 Docker容器化部署
      • 6.3.1 創建Dockerfile
      • 6.3.2 創建.dockerignore文件
      • 6.3.3 構建和運行Docker容器
      • 6.3.4 Docker Compose配置
    • 6.4 云平臺部署
      • 6.4.1 Heroku部署
      • 6.4.2 AWS Elastic Beanstalk部署
  • 7. Node.js性能優化
    • 7.1 代碼優化
      • 7.1.1 異步編程最佳實踐
      • 7.1.2 內存管理
    • 7.2 數據庫優化
    • 7.3 緩存策略

正文

1. Node.js簡介

Node.js是一個基于Chrome V8引擎的JavaScript運行環境,它使JavaScript可以在服務器端運行。Node.js采用事件驅動、非阻塞I/O模型,使其輕量且高效,非常適合構建數據密集型的實時應用程序。

1.1 Node.js的特點

  • 單線程、事件驅動
  • 非阻塞I/O模型
  • 跨平臺(Windows、macOS、Linux)
  • 強大的包管理系統(npm)
  • 高性能處理并發連接

1.2 Node.js架構

Node.js應用程序
Node.js標準庫
Node.js綁定
V8引擎
libuv
事件循環
線程池
JavaScript引擎

2. Node.js安裝

2.1 下載和安裝方法

Node.js有多種安裝方式,針對不同操作系統:

Node.js安裝方式
官方安裝包
包管理器
NVM版本管理
Docker容器
Windows .msi
macOS .pkg
Linux binaries
apt/apt-get
yum/dnf
brew
chocolatey
nvm
n
nodenv

2.1.1 Windows安裝

# 使用Chocolatey包管理器安裝
choco install nodejs# 或使用WinGet安裝
winget install OpenJS.NodeJS

2.1.2 macOS安裝

# 使用Homebrew安裝
brew install node# 也可使用MacPorts
port install nodejs

2.1.3 Linux安裝

# Ubuntu/Debian系統
sudo apt update
sudo apt install nodejs npm# RHEL/CentOS/Fedora系統
sudo dnf install nodejs# Arch Linux
sudo pacman -S nodejs npm

2.2 使用NVM安裝和管理Node.js版本

Node Version Manager (NVM)是一個流行的Node.js版本管理工具,可以方便地安裝和切換不同版本的Node.js。

2.2.1 安裝NVM

# macOS/Linux安裝NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash# 或者使用wget
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash# Windows可使用nvm-windows
# 下載安裝包: https://github.com/coreybutler/nvm-windows/releases

2.2.2 使用NVM管理Node.js

# 查看可用的Node.js版本
nvm ls-remote# 安裝特定版本的Node.js
nvm install 16.14.0# 安裝最新LTS版本
nvm install --lts# 切換Node.js版本
nvm use 14.17.0# 設置默認Node.js版本
nvm alias default 16.14.0# 查看已安裝的版本
nvm ls

2.3 驗證安裝

安裝完成后,可以通過以下命令驗證Node.js和npm是否安裝成功:

# 檢查Node.js版本
node -v# 檢查npm版本
npm -v# 運行簡單的JavaScript代碼
node -e "console.log('Hello, Node.js!')"

3. Node.js環境配置

3.1 npm配置

npm(Node Package Manager)是Node.js默認的包管理工具,可以進行各種配置以優化開發體驗。

3.1.1 基礎npm配置

# 查看當前npm配置
npm config list# 設置npm鏡像源為淘寶鏡像(國內加速)
npm config set registry https://registry.npmmirror.com# 設置全局安裝路徑
npm config set prefix /path/to/global/node_modules# 設置緩存路徑
npm config set cache /path/to/npm/cache# 設置代理(如果需要)
npm config set proxy http://proxy.example.com:8080
npm config set https-proxy http://proxy.example.com:8080

3.1.2 創建.npmrc文件

可以在項目根目錄或用戶主目錄創建.npmrc文件進行配置:

# ~/.npmrc或項目目錄/.npmrc
registry=https://registry.npmmirror.com
save-exact=true
fund=false
audit=false

3.2 package.json配置

package.json是Node.js項目的配置文件,包含項目依賴、腳本等信息。

3.2.1 創建package.json

# 交互式創建package.json
npm init# 創建默認package.json
npm init -y

3.2.2 package.json示例

{"name": "my-node-app","version": "1.0.0","description": "A sample Node.js application","main": "index.js","scripts": {"start": "node index.js","dev": "nodemon index.js","test": "jest","lint": "eslint ."},"keywords": ["node", "example"],"author": "Your Name","license": "MIT","dependencies": {"express": "^4.18.2","dotenv": "^16.0.3","mongoose": "^7.0.0"},"devDependencies": {"nodemon": "^2.0.22","jest": "^29.5.0","eslint": "^8.36.0"},"engines": {"node": ">=14.0.0"}
}

3.3 環境變量配置

3.3.1 使用dotenv管理環境變量

# 安裝dotenv包
npm install dotenv

創建.env文件:

# .env文件
PORT=3000
NODE_ENV=development
DATABASE_URL=mongodb://localhost:27017/myapp
API_KEY=your_secret_api_key

在代碼中使用:

// 在應用入口處盡早加載
require('dotenv').config();// 使用環境變量
const port = process.env.PORT || 3000;
console.log(`Server running on port ${port}`);

3.3.2 不同環境的配置

可以為不同環境創建多個環境配置文件:

.env                # 默認環境
.env.development    # 開發環境
.env.test           # 測試環境
.env.production     # 生產環境

加載特定環境配置:

// 加載特定環境配置
require('dotenv').config({ path: `.env.${process.env.NODE_ENV || 'development'}` });

3.4 調試配置

3.4.1 使用內置調試器

Node.js提供了內置的調試功能:

# 啟動調試模式
node --inspect index.js# 在代碼執行前啟用調試器
node --inspect-brk index.js

然后可以在Chrome瀏覽器中訪問chrome://inspect,連接到Node.js調試實例。

3.4.2 VS Code調試配置

為VS Code創建launch.json配置文件:

{"version": "0.2.0","configurations": [{"type": "node","request": "launch","name": "Launch Program","skipFiles": ["<node_internals>/**"],"program": "${workspaceFolder}/index.js","env": {"NODE_ENV": "development"}},{"type": "node","request": "attach","name": "Attach to Process","port": 9229}]
}

4. 包管理工具

4.1 npm基礎操作

npm是Node.js默認的包管理工具,提供了豐富的功能:

# 安裝依賴
npm install express# 安裝特定版本
npm install express@4.17.1# 安裝開發依賴
npm install --save-dev jest# 全局安裝
npm install -g nodemon# 卸載包
npm uninstall express# 更新包
npm update express# 列出過時的包
npm outdated

4.2 npm腳本配置

package.json中的scripts字段可以定義自定義命令:

"scripts": {"start": "node index.js","dev": "nodemon index.js","test": "jest","lint": "eslint .","build": "webpack --mode production","serve": "node dist/server.js","debug": "node --inspect index.js"
}

運行腳本:

# 運行腳本
npm run dev# 運行預定義腳本可以省略run
npm start
npm test

4.3 yarn

Yarn是Facebook開發的替代npm的包管理工具,具有更快的安裝速度和更好的依賴鎖定。

4.3.1 安裝yarn

# 使用npm安裝yarn
npm install -g yarn# macOS通過Homebrew安裝
brew install yarn

4.3.2 yarn基礎命令

# 初始化項目
yarn init# 安裝依賴
yarn add express# 安裝開發依賴
yarn add --dev jest# 全局安裝
yarn global add nodemon# 卸載包
yarn remove express# 更新包
yarn upgrade express# 運行腳本
yarn start

4.4 pnpm

pnpm是一個快速、節省磁盤空間的包管理器,通過共享依賴降低磁盤占用。

4.4.1 安裝pnpm

# 使用npm安裝pnpm
npm install -g pnpm# 使用curl安裝
curl -fsSL https://get.pnpm.io/install.sh | sh -

4.4.2 pnpm基礎命令

# 初始化項目
pnpm init# 安裝依賴
pnpm add express# 安裝開發依賴
pnpm add -D jest# 全局安裝
pnpm add -g nodemon# 卸載包
pnpm remove express# 更新包
pnpm update express# 運行腳本
pnpm start

4.4.3 包管理器性能比較

graph TDA[包管理器性能比較] --> B[安裝速度]A --> C[磁盤空間]A --> D[鎖文件準確性]A --> E[依賴解析]B --> B1[pnpm > yarn > npm]C --> C1[pnpm > yarn ≈ npm]D --> D1[pnpm ≈ yarn > npm]E --> E1[pnpm ≈ yarn > npm]style A fill:#66CDAAstyle B fill:#87CEFAstyle C fill:#87CEFAstyle D fill:#87CEFAstyle E fill:#87CEFA

5. Node.js項目結構最佳實踐

5.1 標準項目結構

一個組織良好的Node.js項目通常有以下結構:

my-node-project/
├── node_modules/         # 依賴包目錄
├── src/                  # 源代碼目錄
│   ├── config/           # 配置文件
│   ├── controllers/      # 控制器
│   ├── middlewares/      # 中間件
│   ├── models/           # 數據模型
│   ├── routes/           # 路由定義
│   ├── services/         # 業務邏輯
│   ├── utils/            # 工具函數
│   └── index.js          # 應用入口
├── tests/                # 測試文件
│   ├── unit/             # 單元測試
│   └── integration/      # 集成測試
├── public/               # 靜態資源
├── views/                # 視圖模板
├── scripts/              # 實用腳本
├── .env                  # 環境變量
├── .gitignore            # Git忽略文件
├── .eslintrc.js          # ESLint配置
├── .prettierrc           # Prettier配置
├── jest.config.js        # Jest配置
├── nodemon.json          # Nodemon配置
├── package.json          # 項目配置
├── package-lock.json     # 依賴鎖定
└── README.md             # 項目文檔

5.2 模塊化開發實踐

遵循模塊化開發原則,將功能拆分為獨立模塊:

5.2.1 控制器示例

// src/controllers/userController.js
const User = require('../models/User');
const { createToken } = require('../utils/auth');exports.register = async (req, res) => {try {const { name, email, password } = req.body;// 檢查用戶是否已存在const existingUser = await User.findOne({ email });if (existingUser) {return res.status(400).json({ message: '該郵箱已被注冊' });}// 創建新用戶const user = new User({ name, email, password });await user.save();// 生成tokenconst token = createToken(user._id);res.status(201).json({ user: { id: user._id, name, email }, token });} catch (error) {res.status(500).json({ message: '服務器錯誤', error: error.message });}
};exports.login = async (req, res) => {// 登錄邏輯
};exports.getProfile = async (req, res) => {// 獲取用戶資料邏輯
};

5.2.2 路由示例

// src/routes/userRoutes.js
const express = require('express');
const router = express.Router();
const userController = require('../controllers/userController');
const { authenticate } = require('../middlewares/auth');// 公開路由
router.post('/register', userController.register);
router.post('/login', userController.login);// 受保護路由
router.get('/profile', authenticate, userController.getProfile);
router.put('/profile', authenticate, userController.updateProfile);module.exports = router;

5.2.3 應用入口示例

// src/index.js
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const morgan = require('morgan');
require('dotenv').config();// 導入路由
const userRoutes = require('./routes/userRoutes');
const productRoutes = require('./routes/productRoutes');// 初始化應用
const app = express();
const PORT = process.env.PORT || 3000;// 中間件
app.use(cors());
app.use(express.json());
app.use(morgan('dev'));// 路由
app.use('/api/users', userRoutes);
app.use('/api/products', productRoutes);// 錯誤處理中間件
app.use((err, req, res, next) => {console.error(err.stack);res.status(500).send('服務器錯誤!');
});// 連接數據庫
mongoose.connect(process.env.MONGODB_URI, {useNewUrlParser: true,useUnifiedTopology: true,
})
.then(() => {console.log('數據庫連接成功');// 啟動服務器app.listen(PORT, () => {console.log(`服務器運行在 http://localhost:${PORT}`);});
})
.catch((err) => {console.error('數據庫連接失敗:', err);
});

5.3 配置文件管理

集中管理配置參數可以提高維護性:

// src/config/index.js
require('dotenv').config();module.exports = {app: {port: process.env.PORT || 3000,env: process.env.NODE_ENV || 'development',jwtSecret: process.env.JWT_SECRET || 'your-secret-key',jwtExpiration: process.env.JWT_EXPIRATION || '1d',},database: {uri: process.env.MONGODB_URI || 'mongodb://localhost:27017/myapp',options: {useNewUrlParser: true,useUnifiedTopology: true,},},email: {host: process.env.EMAIL_HOST,port: process.env.EMAIL_PORT,user: process.env.EMAIL_USER,password: process.env.EMAIL_PASSWORD,from: process.env.EMAIL_FROM,},// 其他配置...
};

6. Node.js應用部署

6.1 基本部署流程

Node.js應用的部署流程通常包括以下步驟:

準備代碼
打包構建
配置環境變量
選擇部署平臺
安裝依賴
啟動應用
配置反向代理
設置監控

6.2 使用進程管理工具

6.2.1 PM2

PM2是一個流行的Node.js進程管理工具,提供負載均衡、重啟和監控功能。

# 全局安裝PM2
npm install -g pm2# 啟動應用
pm2 start index.js# 啟動應用并命名
pm2 start index.js --name "my-api"# 集群模式啟動(利用多核CPU)
pm2 start index.js -i max# 啟動時配置環境變量
pm2 start index.js --env production# 查看運行中的應用
pm2 list# 監控應用
pm2 monit# 查看應用日志
pm2 logs# 重啟應用
pm2 restart my-api# 停止應用
pm2 stop my-api# 刪除應用
pm2 delete my-api

6.2.2 PM2配置文件

創建ecosystem.config.js文件實現更復雜的配置:

// ecosystem.config.js
module.exports = {apps: [{name: "my-api",script: "src/index.js",instances: "max",exec_mode: "cluster",autorestart: true,watch: false,max_memory_restart: "1G",env: {NODE_ENV: "development"},env_production: {NODE_ENV: "production",PORT: 8080}}]
};

使用配置文件啟動:

pm2 start ecosystem.config.js
# 使用生產環境配置
pm2 start ecosystem.config.js --env production

6.3 Docker容器化部署

6.3.1 創建Dockerfile

# 使用官方Node.js鏡像作為基礎鏡像
FROM node:16-alpine# 設置工作目錄
WORKDIR /usr/src/app# 復制package.json和package-lock.json
COPY package*.json ./# 安裝依賴
RUN npm ci --only=production# 復制應用程序代碼
COPY . .# 暴露端口
EXPOSE 3000# 設置環境變量
ENV NODE_ENV=production# 運行應用
CMD ["node", "src/index.js"]

6.3.2 創建.dockerignore文件

node_modules
npm-debug.log
Dockerfile
.dockerignore
.git
.github
.gitignore
README.md
.env
.env.*
dist
coverage

6.3.3 構建和運行Docker容器

# 構建Docker鏡像
docker build -t my-node-app .# 運行容器
docker run -p 3000:3000 -d --name my-api my-node-app# 查看日志
docker logs my-api# 停止容器
docker stop my-api

6.3.4 Docker Compose配置

創建docker-compose.yml文件實現多容器部署:

version: '3'services:api:build: .ports:- "3000:3000"depends_on:- mongoenvironment:- NODE_ENV=production- MONGODB_URI=mongodb://mongo:27017/myapprestart: alwaysmongo:image: mongo:latestvolumes:- mongodb_data:/data/dbports:- "27017:27017"volumes:mongodb_data:

啟動服務:

docker-compose up -d

6.4 云平臺部署

6.4.1 Heroku部署

Heroku是一個流行的PaaS平臺,提供簡易的Node.js應用部署:

# 安裝Heroku CLI
npm install -g heroku# 登錄Heroku
heroku login# 創建Heroku應用
heroku create my-node-app# 配置環境變量
heroku config:set NODE_ENV=production# 部署代碼
git push heroku main# 查看日志
heroku logs --tail

6.4.2 AWS Elastic Beanstalk部署

AWS Elastic Beanstalk是AWS提供的PaaS服務,支持Node.js應用部署:

# 安裝AWS EB CLI
pip install awsebcli# 初始化EB項目
eb init# 創建環境
eb create my-node-env# 部署代碼
eb deploy# 查看狀態
eb status

7. Node.js性能優化

7.1 代碼優化

7.1.1 異步編程最佳實踐

// 使用async/await處理異步操作
async function getUserData(userId) {try {// 并行請求多個資源const [user, orders, payments] = await Promise.all([User.findById(userId),Order.find({ userId }),Payment.find({ userId })]);return { user, orders, payments };} catch (error) {console.error('獲取用戶數據失敗:', error);throw error;}
}// 避免嵌套回調(回調地獄)
// 不推薦
function processUser(userId, callback) {getUser(userId, (err, user) => {if (err) return callback(err);getOrders(userId, (err, orders) => {if (err) return callback(err);processOrders(orders, (err, result) => {if (err) return callback(err);callback(null, result);});});});
}// 推薦使用Promise
function processUser(userId) {return getUser(userId).then(user => getOrders(userId)).then(orders => processOrders(orders)).catch(error => {console.error('處理用戶數據失敗:', error);throw error;});
}

7.1.2 內存管理

// 避免內存泄漏
const cache = new Map();// 設置緩存上限
const MAX_CACHE_SIZE = 1000;function addToCache(key, value) {// 檢查緩存大小if (cache.size >= MAX_CACHE_SIZE) {// 刪除最早添加的項(簡單實現)const firstKey = cache.keys().next().value;cache.delete(firstKey);}cache.set(key, value);
}// 定期清理資源
const resources = new Map();
let cleanupInterval;function startResourceCleanup() {cleanupInterval = setInterval(() => {const now = Date.now();for (const [key, { value, expires }] of resources.entries()) {if (now > expires) {// 釋放過期資源resources.delete(key);}}}, 60000); // 每分鐘執行一次
}function stopResourceCleanup() {clearInterval(cleanupInterval);
}

7.2 數據庫優化

// 索引優化
// 在Mongoose模型中添加索引
const userSchema = new mongoose.Schema({email: { type: String, unique: true, index: true },username: { type: String, index: true },lastLogin: { type: Date, index: true }
});// 復合索引
userSchema.index({ createdAt: 1, status: 1 });// 查詢優化
// 只獲取需要的字段
const users = await User.find({ status: 'active' }).select('name email');// 使用投影
const orders = await Order.find({}, { items: 0 }); // 排除items字段// 分頁查詢
const PAGE_SIZE = 20;
const page = req.query.page || 1;const products = await Product.find({ category: 'electronics' }).skip((page - 1) * PAGE_SIZE).limit(PAGE_SIZE).lean(); // 返回純JavaScript對象而非Mongoose文檔

7.3 緩存策略

// 使用內存緩存
const NodeCache = require('node-cache');
const cache = new NodeCache({ stdTTL: 600, checkperiod: 120 });async function getProductById(productId) {// 檢查緩存const cachedProduct = cache.get(`product:${productId}`);if (cachedProduct) {return cachedProduct;}// 從數據庫獲取const product = await Product.findById(productId);// 存入緩存cache.set(`product:${productId}`, product, 3600); // 緩存1小時return product;
}// 使用Redis緩存
const Redis = require('ioredis');
const redis = new Redis({host: process.env.REDIS_HOST,port: process.env.REDIS_PORT
});async function getUserProfile(userId) {// 從Redis獲取緩存const cachedProfile = await redis.get(`user:${userId}:profile`);if (cachedProfile) {return JSON.parse(cachedProfile);}// 從數據庫獲取const profile = await User.findById(userId).select('-password');// 存入Redisawait redis.set(`user:${userId}:profile`, JSON.stringify(profile), 'EX', 3600); // 緩存1小時return profile;
}

結語
感謝您的閱讀!期待您的一鍵三連!歡迎指正!

在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/pingmian/81646.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/81646.shtml
英文地址,請注明出處:http://en.pswp.cn/pingmian/81646.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Neo4j(一) - Neo4j安裝教程(Windows)

文章目錄 前言一、JDK與Neo4j版本對應關系二、JDK11安裝及配置1. JDK11下載2. 解壓3. 配置環境變量3.1 打開系統屬性設置3.2 新建系統環境變量3.3 編輯 PATH 環境變量3.4 驗證環境變量是否配置成功 三、Neo4j安裝&#xff08;Windows&#xff09;1. 下載并解壓Neo4j安裝包1.1 下…

深信服golang面經

for range 中賦值的變量&#xff0c;這個變量指向的是真實的地址嗎&#xff0c;還是臨時變量 不是真實地址&#xff0c;是臨時變量 package mainimport "fmt"func main() {slice : []int{4, 2, 3}for _, v : range slice {fmt.Println(v, &v) // 這里的 v 是臨…

PLC雙人舞:profinet轉ethernet ip網關奏響施耐德與AB的協奏曲

PLC雙人舞&#xff1a;ethernet ip轉profinet網關奏響施耐德與AB的協奏曲 案例分析&#xff1a;施耐德PLC與AB PLC的互聯互通 在現代工業自動化中&#xff0c;設備之間的互聯互通至關重要。本案例旨在展示如何通過北京倍訊科技的EtherNet/IP轉Modbus網關&#xff0c;將施耐德P…

鏈接家里電腦

要在外網訪問家里的電腦&#xff08;或NAS&#xff09;&#xff0c;主要有 5種主流方法&#xff0c;各有優缺點&#xff0c;適用于不同需求。以下是詳細方案和操作指南&#xff1a; 一、方案對比速查表 方法適用場景速度安全性難度是否需要公網IP遠程桌面&#xff08;RDP&…

VS Code開源AI編輯器:一場編程革命的新起點

在2025年5月19日&#xff0c;微軟發布了一則激動人心的消息——VS Code將開源其AI編輯器組件&#xff0c;特別是GitHub Copilot Chat擴展。正如微軟官方博客所宣告的&#xff1a;“我們相信代碼編輯器的未來應該是開放的&#xff0c;并由AI驅動。” 為什么現在開源&#xff1f…

51c嵌入式※~合集7~Linux

我自己的原文哦~ https://blog.51cto.com/whaosoft/13926843 一、u-boot和bootloader~區別 Bootloader 比Bootloader從字面上來看就是啟動加載的意思。用過電腦的都知道&#xff0c;windows開機時會首先加載bios&#xff0c;然后是系統內核&#xff0c;最后啟動完畢。那…

深度學習實戰 04:卷積神經網絡之 VGG16 復現三(訓練)

在后續的系列文章中&#xff0c;我們將逐步深入探討 VGG16 相關的核心內容&#xff0c;具體涵蓋以下幾個方面&#xff1a; 卷積原理篇&#xff1a;詳細剖析 VGG 的 “堆疊小卷積核” 設計理念&#xff0c;深入解讀為何 332 卷積操作等效于 55 卷積&#xff0c;以及 333 卷積操作…

Ubuntu 20.04之Docker安裝ES7.17.14和Kibana7.17.14

你需要已經安裝如下運行環境: Ubuntu 20.04 docker 28 docker-compose 1.25 一、手動拉取鏡像 docker pull docker.elastic.co/kibana/kibana:7.17.14docker pull docker.elastic.co/elasticsearch/elasticsearch:7.17.14 或者手動導入鏡像 docker load -i es7.17.14.ta…

實時技術方案對比:SSE vs WebSocket vs Long Polling

早期網站僅展示靜態內容,而如今我們更期望:實時更新、即時聊天、通知推送和動態儀表盤。 那么要如何實現實時的用戶體驗呢?三大經典技術各顯神通: SSE(Server-Sent Events):輕量級單向數據流WebSocket:雙向全雙工通信Long Polling(長輪詢):傳統過渡方案假設目前有三…

測試開發面試題:Python高級特性通俗講解與實戰解析

前言&#xff1a;為什么測試工程師必須掌握Python高級特性&#xff1f; 通俗比喻&#xff1a; 基礎語法就像“錘子”&#xff0c;能敲釘子&#xff1b;高級特性就像“瑞士軍刀”&#xff0c;能應對復雜場景&#xff08;如自動化框架、高并發測試&#xff09;。面試官考察點&a…

C語言-9.指針

9.1指針 9.1-1取地址運算:&運算符取得變量的地址 運算符& scanf(“%d”,&i);里的&獲取變量的地址,它們操作數必須是變量int i;printf(“%x”,&i);地址的大小是否與int相同取決于編譯器int i;printf(“%p”,&i); &不能取的地址不能對沒有地址的…

【C++】Vcpkg 介紹及其常見命令

Vcpkg 簡介 Vcpkg 是微軟開發的一個跨平臺的 C/C 依賴管理工具&#xff0c;用于簡化第三方庫的獲取、構建和管理過程。 主要特點 跨平臺支持&#xff1a;支持 Windows、Linux 和 macOS開源免費&#xff1a;MIT 許可證大型庫集合&#xff1a;包含超過 2000 個開源庫簡化集成&…

Unity3D 動畫文件優化總結

前言 在Unity3D中&#xff0c;動畫文件的壓縮和優化是提升性能的重要環節&#xff0c;尤其在移動端或復雜場景中。以下是針對Animation Clip和Animator Controller的優化方法總結&#xff1a; 對惹&#xff0c;這里有一個游戲開發交流小組&#xff0c;希望大家可以點擊進來一…

前端工程的相關管理 git、branch、build

環境配置 標準環境打包 測試版&#xff1a;npm run build-test 預生產&#xff1a;npm run build-preview 正式版&#xff1a;npm run build 建議本地建里一個 .env.development.local 方便和后端聯調時修改配置相關信息。 和 src 同級有一下區分環境的文件&#xff1a; .env.d…

VAPO:視覺-語言對齊預訓練(對象級語義)詳解

簡介 多模態預訓練模型(Vision-Language Pre-training, VLP)近年來取得了飛躍發展。在視覺-語言模型中,模型需要同時理解圖像和文本,這要求模型學習二者之間的語義對應關系。早期方法如 VisualBERT、LXMERT 等往往使用預先提取的圖像區域特征和文本詞嵌入拼接輸入,通過 T…

docker運行Redis

創建目錄 mkdir -p /home/jie/docker/redis/{conf,data,logs}添加權限 chmod -R 777 /home/jie/docker/redis創建配置文件 cat > /home/jie/docker/redis/conf/redis.conf << EOF # 基本配置 bind 0.0.0.0 protected-mode yes port 6379# 安全配置 密碼是root require…

初識 java

目錄 前言 一、jdk&#xff0c;JRE和JVM之間的關系 二、JVM的內存劃分 前言 初步了解 jdk&#xff0c;JRE&#xff0c;JVM 之間的關系&#xff0c;JVM 的內存劃分。 一、jdk&#xff0c;JRE和JVM之間的關系 jdk 是 java 開發工具集&#xff0c;包含JRE&#xff1b; JRE 是…

關于百度地圖JSAPI自定義標注的圖標顯示不完整的問題(其實只是因為圖片尺寸問題)

下載了幾個阿里矢量圖標庫里的圖標作為百度地圖的自定義圖標&#xff0c;結果百度地圖顯示的圖標一直不完整。下載的PNG圖標已經被正常引入到前端代碼&#xff0c;anchor也設置為了圖標底部中心&#xff0c;結果還是顯示不完整。 if (iconUrl) {const icon new mapClass.Icon(…

系統安全及應用深度筆記

系統安全及應用深度筆記 一、賬號安全控制體系構建 &#xff08;一&#xff09;賬戶全生命周期管理 1. 冗余賬戶精細化治理 非登錄賬戶基線核查 Linux 系統默認創建的非登錄賬戶&#xff08;如bin、daemon、mail&#xff09;承擔系統服務支撐功能&#xff0c;其登錄 Shell 必…

02-前端Web開發(JS+Vue+Ajax)

介紹 在前面的課程中&#xff0c;我們已經學習了HTML、CSS的基礎內容&#xff0c;我們知道HTML負責網頁的結構&#xff0c;而CSS負責的是網頁的表現。 而要想讓網頁具備一定的交互效果&#xff0c;具有一定的動作行為&#xff0c;還得通過JavaScript來實現。那今天,我們就來講…