定制模版-001
⏱️最后更新: 2025/07/27
目录
目录结构:templates/advanced-001/
templates/advanced-001/
├── package.json
├── README.md
├── src/
│ ├── index.js
│ └── util.js
├── tests/
│ └── test.js
└── .gitignore
package.json
:
json
{
"name": "advanced-template",
"version": "1.0.0",
"type": "module",
"main": "src/index.js",
"scripts": {
"start": "node src/index.js",
"test": "node tests/test.js"
},
"dependencies": {
"express": "^4.18.2"
}
}
README.md
:
markdown
# Advanced Template
这是一个带有常用功能的 Node.js 项目模板,支持 Express 等模块。
## 使用方法
- 安装依赖:`npm install`
- 运行项目:`npm start`
- 运行测试:`npm test`
src/index.js
:
js
// src/index.js
import express from "express";
const app = express();
app.get("/", (req, res) => {
res.send("Hello from Advanced Template!");
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
});
src/util.js
:
js
// src/util.js
export function greet(name) {
return `Hello, ${name}!`;
}
tests/test.js
:
js
// tests/test.js
import { greet } from "../src/util.js";
console.log(greet("World"));