慣性聚合 高效追讀感興趣之博客、新聞、科技資訊
閱原文 以慣性聚合開啟

推薦訂閱源

博客园 - 司徒正美
V
V2EX
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
aimingoo的专栏
aimingoo的专栏
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
月光博客
月光博客
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python)
全Next.js与Node.js及PostgreSQL面试任务之设
Parth Kathro · 2026-05-24 · via DEV Community

技术栈:
前端:Next.js

  • 后端:Node.js + Express.js
  • 数据库:PostgreSQL
  • 对象关系映射:Sequelize
  • 面试技术环节项目流程
  1. 创建前端
    npx create-next-app@latest frontend
    touch .env

  2. 创建后端 & 装后端依賴
    mkdir backend
    cd backend
    npm init -y
    npm install express cors dotenv bcryptjs jsonwebtoken pg pg-hstore sequelize
    npm install -D nodemon sequelize-cli

  3. 後端目錄結構指令
    mkdir config controllers middleware models routes migrations seeders
    touch server.js
    touch config/db.js
    touch middleware/authMiddleware.js
    touch controllers/authController.js
    touch controllers/*.js
    touch controllers/*.js
    touch routes/authRoutes.js
    touch routes/*.js
    touch routes/*.js
    touch .env

    前端依賴
    cd frontend
    npm install axios react-hot-toast
    touch .env

    若欲设 Tailwind,则往 Tailwind 之网站,择 v3 版本而为之。

  4. package.json 脚本
    "脚本": {
    "始": "啟 node server.js"
    "dev":"nodemon server.js"
    }

  5. Sequelize初始化&PostgreSQL數據庫創建
    npx sequelize-cli init
    是故生焉:
    config/
    models/
    migrations/
    seeders/

    啟 PostgreSQL 终端:
    創建數據庫 employee_management;

  6. 後端 與 前端 .env 文件
    後端:

PORT=5000
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=yourpassword
DB_NAME=employee_management
JWT_SECRET=mysecretkey

進入全屏模式 退出全屏模式

前端:
NEXT_PUBLIC_BASE_URL=http://localhost:5000
PostgreSQL 用 Sequelize 配置
config/config.json

{
  "development": {
    "username": "postgres",
    "password": "",
    "database": "",
    "host": "localhost",
    "dialect": "postgres"
  }
}

入全景模式 出全景模式

  1. 数据库连接 config/db.js
const { Sequelize } = require("sequelize");
require("dotenv").config();

const sequelize = new Sequelize(
  process.env.DB_NAME,
  process.env.DB_USER,
  process.env.DB_PASSWORD,
  {
    host: process.env.DB_HOST,
    port: process.env.DB_PORT,
    dialect: "postgres",
    logging: false,
  }
);

module.exports = sequelize;

入全景模式 出全景模式

  1. 生成模型与迁移&运行迁移
    用户模型
    npx sequelize-cli model:generate --name User --attributes name:string,email:string,password:string
    运行迁移
    npx sequelize-cli db:migrate

  2. Express服务器设置
    server.js

const express = require("express");
const cors = require("cors");

require("dotenv").config();

const app = express();

app.use(cors());

app.use(express.json());

app.use("/api/auth", require("./routes/authRoutes"));

app.use("/api/employees", require("./routes/employeeRoutes"));

app.use("/api/attendance", require("./routes/attendanceRoutes"));

const PORT = process.env.PORT || 5000;

app.listen(PORT, () => {
  console.log(`Server running on ${PORT}`);
});

进入全屏模式 退出全屏模式

  1. 身份验证中间件 middleware/authMiddleware.js
const jwt = require("jsonwebtoken");

module.exports = (req, res, next) => {
  try {
    const token = req.headers.authorization?.split(" ")[1];

    if (!token) {
      return res.status(401).json({
        message: "No token provided",
      });
    }

    const decoded = jwt.verify(
      token,
      process.env.JWT_SECRET
    );

    req.user = decoded;

    next();
  } catch (error) {
    res.status(401).json({
      message: "Invalid token",
    });
  }
};

入全景模式 出全景模式

  1. 登录控制器 controllers/authController.js
const bcrypt = require("bcryptjs");

const jwt = require("jsonwebtoken");

const { User } = require("../models");

exports.login = async (req, res) => {
  try {
    const { email, password } = req.body;

    const user = await User.findOne({
      where: { email },
    });

    if (!user) {
      return res.status(400).json({
        message: "User not found",
      });
    }

    const isMatch = await bcrypt.compare(
      password,
      user.password
    );

    if (!isMatch) {
      return res.status(400).json({
        message: "Invalid credentials",
      });
    }

    const token = jwt.sign(
      { id: user.id },
      process.env.JWT_SECRET,
      {
        expiresIn: "1d",
      }
    );

    res.json({
      token,
      user,
    });
  } catch (error) {
    res.status(500).json({
      message: error.message,
    });
  }
};

入全景模式 出全景模式

  1. 认证路由 routes/authRoutes.js
const router = require("express").Router();

const controller = require("../controllers/authController");

router.post("/login", controller.login);

module.exports = router;

12. Axios Setup
src/utils/axios.js
import axios from "axios";

const api = axios.create({
  baseURL: process.env.NEXT_PUBLIC_BASE_URL,
});

api.interceptors.request.use((config) => {
  const token = localStorage.getItem("token");

  if (token) {
    config.headers.Authorization = `Bearer ${token}`;
  }

  return config;
});

export default api;

入全景模式 出全景模式

  1. React路由设置 src/app/App.js
import {
  createBrowserRouter,
  Navigate,
  RouterProvider 
} from "react-router-dom";
import React from "react";
import ReactDOM from "react-dom/client";

import Login from "./pages/Login";
import Register from "./pages/Register";
import Home from "./pages/Home";
import Profile from "./pages/Profile";

function PrivateRoute({ children }) {

  const isLoggedIn = localStorage.getItem("token");

  return isLoggedIn
    ? children
    : <Navigate to="/login" />;
}

function PublicRoute({ children }) {

  const isLoggedIn = localStorage.getItem("token");

  return isLoggedIn
    ? <Navigate to="/" />
    : children;
}

const router = createBrowserRouter([
  {
    path: "/login",
    element: (
      <PublicRoute>
        <Login />
      </PublicRoute>
    ),
  },

  {
    path: "/register",
    element: (
      <PublicRoute>
        <Register />
      </PublicRoute>
    ),
  },

  {
    path: "/",
    element: (
      <PrivateRoute>
        <Home />
      </PrivateRoute>
    ),
  },

  {
    path: "/profile",
    element: (
      <PrivateRoute>
        <Profile />
      </PrivateRoute>
    ),
  },
]);

function App() {
  return (
    <div>
    <RouterProvider router={router} />
    </div>
  );
}

export default App;

入全屏模式 出全屏模式

  1. 登录API示例 src/app/login/login.js
import api from "@/utils/axios";
import { useRouter } from "next/navigation";

const router = useRouter();

const login = async () => {
  const res = await api.post("/auth/login", {
    email,
    password,
  });

  localStorage.setItem(
    "token",
    res.data.token
  );

router.push("/");
};

入全屏模式 出全屏模式

  1. 登出函数
import { useRouter } from "next/navigation";

const router = useRouter();
const logout = () => {
  localStorage.removeItem("token");

  router.push("/login");
};

入全屏模式 出全屏模式

示例

  1. Next.js路由 src/app/login/page.js

源码/app/仪表盘/页.js

源码/app/职员/页.js

  1. 登录后重定向 导入{路由器}自"next/navigation"

常量路由器=路由器()

路由器推入"/仪表盘"

  1. 重要PostgreSQL指令 开启PostgreSQL psql -U postgres

显示数据库
\l

连接数据库
员工管理

显诸表
\dt

  1. 迁徙之令 行迁徙 npx sequelize-cli db:migrate

撤回上一次迁移
npx sequelize-cli db:migrate:undo

撤回所有迁移
npx sequelize-cli db:migrate:undo:all

  1. 原始查询示例 const sequelize = require("../config/db");

const [employees] = await sequelize.query(
'SELECT * FROM "Employees"'
);

console.log(employees);

  1. Sequelize Query ExamplesCreateawait Employee.create({name: "Parth",email: "parth@gmail.com"});

Find All
await Employee.findAll();

Find One
待寻雇员其一,其条件为
何处:{
id:一,
},
});

更新
待 Employee 更新
{
名:"更新",
},
{
何处:{
id:一,
},

});

Delete

Employee.destroy({

where: {__JHSNS_SEG_f0456e12_123__ __JHSNS_SEG_f0456e12_124__id: 1,

  1. });__JHSNS_SEG_f0456e12_126__Example Migration File

migrations/XXXXXXXXXXXX-create-user.js __JHSNS_SEG_f0456e12_127__"use strict";__JHSNS_SEG_f0456e12_127__module.exports = {
俟之,上之 queryInterface, Sequelize
俟之, queryInterface 营 "Users" 表,其制如左
id:{
不可释,
自增,
为主键,
数为 Sequelize.INTEGER,
}

  name: {
    type: Sequelize.STRING,
  },

  email: {
    type: Sequelize.STRING,
    unique: true,
  },

  password: {
    type: Sequelize.STRING,
  },

  createdAt: {
    allowNull: false,
    type: Sequelize.DATE,
  },

  updatedAt: {
    allowNull: false,
    type: Sequelize.DATE,
  },
});

退出全屏模式

},

异步下(queryInterface, Sequelize) {
期待 queryInterface.dropTable("Users");
},
};

  1. 示例模型文件 models/user.js "use strict";

const { Model } = require("sequelize");

module.exports = (sequelize, DataTypes) => {
乃立类曰用户,承于模也。
静联诸模,无他。
}

用户既立,启之,
{
名者,为文也。

  email: DataTypes.STRING,

  password: DataTypes.STRING,
},
{
  sequelize,
  modelName: "User",
}

全屏入 全屏出

});

返用户之立也。
};

  1. 载入模型之用 const db = require("../models"); const { User, Employee, Attendance } = db;

Tailwind设其核于React

  1. 装Tailwind CSS v3
    npm install -D tailwindcss@3

  2. 造Tailwind配置之文
    npx tailwindcss init
    此造:
    tailwind.config.js

  3. 設置範本路徑
    於tailwind.config.js之內
    /** @type {import('tailwindcss').Config} /
    export default {
    內容: ["./src/
    /.{html,js,jsx}"],
    主題: {
    延展: {},
    },
    插件: []
    }

  4. 入索引CSS文件
    创:
    src/index.css
    增:
    @tailwind base;
    @tailwind components;
    @tailwind utilities;

  5. 始Tailwind构建之程
    行:
    npx tailwindcss -i ./src/input.css -o ./src/output.css --watch
    此令也:
    自输入之CSS中读Tailwind之类别
    生成最终之CSS,入output.css。
    时计以观变