Node.js?? ??? ?? ???? ????? Node.js ?? ???? API ?? ? ???? ?? ??? ?????. ??? Node.js? ???? ??? ?? ???? ???? ??? ?? ??? ??? ??????.
1??: ?? ?? ??
??? ???? ?? ???? ??? ???? ???.
- Node.js: ?? ??? JavaScript? ???? ?? ??????. nodejs.org?? ????? ? ????.
- NPM(?? ??? ???): Node.js? ?? ??? ?????. ?????? ???? ???? ? ?????.
Node.js? NPM? ???? ??? ????? ??? ?????.
node -v npm -v
??? ?? ?? ??? ?????. ??? ??? Node.js? ?????.
2??: ? ???? ???
- ???? ?? ???:
mkdir my-custom-backend cd my-custom-backend
- package.json ?? ???:
npm init -y
? ??? ???? ???? ?? package.json ??? ?????.
3??: ?? ??? ??
???? ????? ?? ???? ???? ???.
- Express: ? ? ??? ?????? ??? ?? ??? ?? ??? ???? ???? ??? Node.js ? ?????? ????????.
- Nodemon: ????? ?? ??? ???? ??? ???? ?? ???? Node.js ?????? ??? ?? ?????.
- Body-parser: JSON ? URL ???? ?? ???? ???? ???????.
- dotenv: ????? ?????.
??? ???? ??? ???? ?????.
npm install express body-parser dotenv npm install --save-dev nodemon
- express: HTTP ??? ???? ?? ?????.
- body-parser: ??? ??? ?????? ???? ??? ?? ???? ?? ?????, req.body? ?? ???? ? ????.
- dotenv: .env ??? ?? ??? process.env? ?????.
- nodemon: ??? ???? ???? ??? ?? ?????(?? ????).
4??: ?? ?? ??
???? ??? server.js?? ??? ?????. ? ??? Express ?? ??? ?????.
touch server.js
server.js ??? ?? ??? ?????.
// Import necessary modules const express = require('express'); const bodyParser = require('body-parser'); const dotenv = require('dotenv'); // Load environment variables dotenv.config(); // Initialize the app const app = express(); // Middleware to parse JSON data app.use(bodyParser.json()); // Define a basic route app.get('/', (req, res) => { res.send('Welcome to my custom Node.js backend!'); }); // Start the server const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}`); });
? ??? ??? ???? ??? ???? ???? Express ??? ?????.
5??: ?? ??
??? ????? node ??? ??? ? ????.
node -v npm -v
??? ??? ???? nodemon? ???? ?? ? ???? ??? ?? ???? ?? ????.
mkdir my-custom-backend cd my-custom-backend
?? ?????? http://localhost:3000? ?????. ??? ?????.
npm init -y
6??: ?? ? ??? ??
???? ???? ?? ? ?? ??? ?? ??? ???? ???. ?? ??, ??? ??? ???? API? ?? ? ????.
npm install express body-parser dotenv npm install --save-dev nodemon
- GET /users: ?? ???? ?????.
- GET /users/:id: ID? ???? ?????.
- POST /users: ? ???? ?????.
- DELETE /users/:id: ID?? ???? ?????.
7??: ?? ?? ??
dotenv ???? ???? ?? ??? ??? ? ????. ?? ????? .env ??? ????.
touch server.js
.env ??? ??? ?? ??? ??? ? ????.
// Import necessary modules const express = require('express'); const bodyParser = require('body-parser'); const dotenv = require('dotenv'); // Load environment variables dotenv.config(); // Initialize the app const app = express(); // Middleware to parse JSON data app.use(bodyParser.json()); // Define a basic route app.get('/', (req, res) => { res.send('Welcome to my custom Node.js backend!'); }); // Start the server const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}`); });
? ??? server.js?? ??? ???? ???? ? ?????.
node server.js
8??: ?? ?? ? ???? ??
Express? ????? ??????? ??-?? ???? ?? ??(req), ?? ??(res), ?? ???? ??? ???? ?????.
?? ??? ?? ??? ?? ????? ??? ? ????.
npx nodemon server.js
???????? ???? ?? ??? ???? 500 ?? ??? ?????.
9??: ???? ??(?? ??)
???? ???? ???? ???? ?? ????.
Welcome to my custom Node.js backend!
- controllers/: API ??? ?? ??? ?????.
- routes/: ?????? ???? ?? ????? ?????.
- models/: ??? ??? ???? ?? ??????? ??? ?? ????.
10??: ??????? ??(?? ??)
???? ????? ???? ??????? ??? ? ????. ?:
- MongoDB: Mongoose? ???? MongoDB ??????? ???????.
- MySQL/PostgreSQL: Sequelize ?? pg? ???? SQL ??????? ?? ?????.
MongoDB? ?? mongoose? ?????.
// Example user data let users = [ { id: 1, name: 'John Doe' }, { id: 2, name: 'Jane Doe' } ]; // Route to get all users app.get('/users', (req, res) => { res.json(users); }); // Route to get a user by ID app.get('/users/:id', (req, res) => { const userId = parseInt(req.params.id); const user = users.find((u) => u.id === userId); if (user) { res.json(user); } else { res.status(404).send('User not found'); } }); // Route to create a new user app.post('/users', (req, res) => { const newUser = { id: users.length + 1, name: req.body.name }; users.push(newUser); res.status(201).json(newUser); }); // Route to delete a user by ID app.delete('/users/:id', (req, res) => { const userId = parseInt(req.params.id); users = users.filter((u) => u.id !== userId); res.status(204).send(); });
server.js??:
touch .env
11??: Postman ?? Curl? ???? API ???
API? ?????? Postman ?? ?? ??? ? ????.
PORT=3000
?? ???? ??? ? ? ?? GUI? ???? Postman? ??? ?? ????.
12??: ??? ??
???? ???? ??? ?? ???? ???? ???? ??? ? ????.
- Heroku: ?? ??? ??.
- AWS EC2: ??? ?? ??? ?????.
- DigitalOcean: ??? ???? ????.
??? ?? PORT? ????, API ?? ?? ??? ??? ?? ??? ???? ??? ?????.
??
??? ??? ??? ?? Node.js? ???? ?? ??? ?? ???? ???? ?????. ??? ????, ??????? ????, WebSocket? ?? ??? ??? ?? ?? ??? ???? ?? ?? ??? ? ????.
? ??? Node.js? ??? ?? ??? ??: ??? ???? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

JavaScript? ??? ?? ????? ??? ?? ??? ??? ?? ?? ?? ????? ?? ???? ???? ?????. ??? ?? ???? ?? ??? ?? ??? ???? ???? ?? ?? ???? ???? ?????. ?? ??, ??? ? ?? ???? ??? (? : ??? null? ??) ?? ??? ????? ??????. ??? ??? ???? ??? ??? ????. closure?? ?? ??? ?? ??; ? ??? ??? ?? ?? ???? ?? ???? ????. V8 ??? ?? ???, ?? ??, ??/?? ???? ?? ??? ?? ??? ??? ????? ?? ??? ?? ??? ????. ?? ?? ???? ??? ??? ??? ??? ???? ????? ?? ?? ???? ?? ???????.

Node.js?? HTTP ??? ???? ? ?? ???? ??? ????. 1. ?? ????? ????? ??? ??? ? ?? ????? ?? ?? ? https.get () ??? ?? ??? ??? ? ?? ????? ?? ??? ?????. 2.axios? ??? ???? ? ?? ??????. ??? ??? ??? ??? ??? ??? ???/???, ?? JSON ??, ???? ?? ?????. ??? ?? ??? ????? ?? ????. 3. ?? ??? ??? ??? ??? ???? ???? ??? ??? ???? ?????.

JavaScript ??? ??? ?? ?? ? ?? ???? ????. ?? ???? ???, ??, ??, ?, ???? ?? ? ??? ?????. ?? ????? ?? ?? ? ? ??? ????? ?? ??? ??? ????. ??, ?? ? ??? ?? ?? ??? ??? ??? ???? ??? ??? ???? ??? ?? ??? ????. ?? ? ????? ??? ???? ? ??? ? ??? TypeofNull? ??? ?????? ??? ? ????. ? ? ?? ??? ???? ?????? ????? ???? ??? ???? ? ??? ? ? ????.

?????, JavaScript ???! ?? ? JavaScript ??? ?? ?? ?????! ?? ?? ??? ??? ??? ? ????. Deno?? Oracle? ?? ??, ??? JavaScript ?? ??? ????, Google Chrome ???? ? ??? ??? ???? ?????. ?????! Deno Oracle? "JavaScript"??? ????? Oracle? ?? ??? ??? ??????. Node.js? Deno? ??? ? Ryan Dahl? ??? ?????? ???? ????? JavaScript? ??? ???? Oracle? ????? ???? ?????.

?? JavaScript ??? ??? ??? ?????? ?? ??? ?? ?? ??? ?? ???? ????. 1. ??? ???? ???? ?? ??? ?? ? ? ???? ??? ??? ?? ? ?? ????? ?????. 2. Angular? ?????? ??? ?? ???? ? ?? ?? ??? ??? ??? ???? ?????. 3. VUE? ???? ?? ??? ???? ?? ?? ??? ?????. ?? ?? ?? ??, ? ??, ???? ???? ? SSR? ???? ??? ??? ??? ???? ? ??? ?????. ???, ??? ??? ??? ????? ????. ??? ??? ??? ??? ?? ????.

iife (?? invokedfunctionexpression)? ?? ??? ???? ?? ????? ??? ???? ?? ??? ????? ?? ??? ? ?????. ??? ?? ?? ??? ???? ? ?? ??? ??? ?? (function () {/code/}) ();. ?? ???? ??? ?????. 1. ?? ??? ??? ?? ???? ?? ??? ??? ?????. 2. ?? ??? ??? ???? ?? ?? ??? ????. 3. ?? ?? ??? ????? ?? ???? ???????? ?? ? ??. ???? ?? ???? ?? ??? ES6 ??? ??? ??? ?? ? ??? ????? ??? ? ???? ???????.

??? JavaScript?? ??? ??? ?????? ?? ???????. ?? ??, ?? ?? ? ??? ??? ?? ????? ????? ?????. 1. ?? ??? ??? ????? ???? ??. ()? ?? ??? ??? ?????. ?. ()? ?? ??? ?? ??? ??? ?? ? ? ????. 2. ?? ??? .catch ()? ???? ?? ??? ??? ?? ??? ??????, ??? ???? ???? ????? ??? ? ????. 3. Promise.all ()? ?? ????? (?? ?? ?? ? ??????? ??), Promise.Race () (? ?? ??? ?? ?) ? Promise.AllSettled () (?? ??? ???? ??)

Cacheapi? ?????? ?? ???? ??? ???? ???, ?? ??? ??? ?? ???? ? ??? ?? ? ???? ??? ??????. 1. ???? ????, ??? ??, ?? ?? ?? ???? ???? ??? ? ????. 2. ??? ?? ?? ??? ?? ? ? ????. 3. ?? ?? ?? ?? ?? ??? ??? ?? ?????. 4. ??? ???? ?? ?? ???? ?? ?? ?? ?? ?? ???? ?? ?? ??? ??? ? ????. 5. ?? ???? ??, ??? ??? ? ??? ??, ?? ??? ? ?? ???? ???? ???? ? ?? ?????. 6.?? ??? ?? ?? ?? ??, ???? ?? ? HTTP ?? ????? ?????? ???????.
