# JNode **Repository Path**: NidhoggDJoking/node ## Basic Information - **Project Name**: JNode - **Description**: Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. - **Primary Language**: JavaScript - **License**: Apache-2.0 - **Default Branch**: mac - **Homepage**: https://nidhoggdjoking.gitee.io/evolution/#/ - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-11-04 - **Last Updated**: 2023-05-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: Nodejs, Express ## README # JNode [Express中文网手册](https://www.expressjs.com.cn/starter/installing.html) - ### 初始化 ```javascript // app.js const express = require('express') const app = express() const port = 3000 app.get('/', (req, res) => { res.send('Hello World!') }) app.listen(port, () => { console.log(`Example app listening at http://localhost:${port}`) }) ``` ```bash node app.js ``` - ### 数据层 处理获取的数据 ```javascript // 利用JSON.stringify()把对象转为对象字符串,可去掉RowDataPacket console.log(JSON.parse(JSON.stringify(rows))) // 该操作是可以去掉查询语句默认的RowDataPacket ``` 防注入 ```javascript // 这种方式 mysql 模块内部会调用 escape 方法,过滤掉一些非法的操作 connection.query("select * from users where id = ? and name = ?", [1, 'xxx'], (err, result)=>{}) // 当前我们也可以自己使用 escape 方法 connection.query('select * from users where id = ' + connection.escape(userId), (err, result) => {}) // 或者 format 方法 const sql = "select * from ?? where ?? = ?" const inserts = ['users', 'id', 1] sql = mysql.format(sql, inserts) // select * from users where id = 1 ```