标签:yam mys use 部分 ejs bst ast als inf
快速,简单,极简的节点Web框架
1100万
const cheerio = require(\’cheerio\’);
const $ = cheerio.load(\’
\’);
420万
const nodemailer = require("nodemailer");
let testAccount = await nodemailer.createTestAccount();
let transporter = nodemailer.createTransport({
host: "smtp.ethereal.email",
port: 587,
secure: false,
auth: {
user: testAccount.user,
pass: testAccount.pass
}
});
let info = await transporter.sendMail({
from: \‘"Fred Foo " <foo@example.com>\‘,
to: "bar@example.com, baz@example.com",
subject: "Hello ?",
text: "Hello world?",
html: "Hello world?"
});
98万
const server = require(\‘http\‘).createServer();
const io = require(\‘socket.io\‘)(server);
io.on(\‘connection\‘, client => {
client.on(\‘event\‘, data => { ... });
client.on(\‘disconnect\‘, () => { ... });
});
server.listen(3000);
· 实施实时分析,二进制流,实例消息传递和文档协作
· 知名用户包括Microsoft Office,Yammer和Zendesk
3M
var faker = require(\‘faker\‘);
var randomName = faker.name.findName(); // Rowan Nikolaus
var randomEmail = faker.internet.email(); // Kassandra@erich.biz
var randomCard = faker.helpers.createCard(); // random contact card
· 在API后端构建尚未完成的情况下构建前端UI并与数据进行交互
· 多种API方法,包括地址,公司,数据库,图像,名称(firstName,lastName)
140万
例如GET / 200 51.267 ms — 1539
morgan
(\‘:method :url :status :res[content-length] - :response-time ms\‘)
---
var express = require(\‘express\‘)
var morgan = require(\‘morgan\‘)
var app = express()
app.use(morgan(\‘combined\‘))
app.get(\‘/\‘, function (req, res) {
res.send(\‘hello, world!\‘)
})
· 将请求记录在控制台,文件,数据库中
· 调试和日志历史记录
2M
app.use(function (req, res, next) {
if (!req.user)
return next(createError(401, \‘Please login to view this page.\‘))
next()
})
· 易于发送错误响应
· 许多错误属性可用
expose
headers
message
status
statusCode
27M
在处理程序之前在中间件中解析传入的请求主体,该处理程序在req.body属性下可用
var express = require(\‘express\‘)
var bodyParser = require(\‘body-parser\‘)
var app = express()
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
· 解释请求正文
· 许多选项,例如inflate,type,verify
1300万
它具有可靠的事务支持,关系,急切和延迟加载,读取复制等功能
const sequelize = new Sequelize
(\‘database\‘, \‘username\‘, \‘password\‘,
{
host: \‘localhost\‘,
dialect: /* one of \‘mysql\‘
| \‘mariadb\‘ | \‘postgres\‘ | \‘mssql\‘ */ });
· Node.js ORM
720K
Passport的唯一目的是对请求进行身份验证,它通过一组称为策略的可扩展插件来完成
passport.use(new LocalStrategy(
function(username, password, done) {
User.findOne({ username: username }, function (err, user) {
if (err) { return done(err); }
if (!user) { return done(null, false); }
if (!user.verifyPassword(password)) { return done(null,
false); }
return done(null, user);
});
}
));
· Node.js身份验证
· 与OAuth和OpenID集成(Facebook,Twitter等…登录)
810K
将配置与代码分开存储在环境中
require(\‘dotenv\‘).config()
const db = require(\‘db\‘)
db.connect({
host: process.env.DB_HOST,
username: process.env.DB_USER,
password: process.env.DB_PASS
})
// .env file
DB_HOST=localhost
DB_USER=root
DB_PASS=s1mpl3
· 加载环境变量,例如AWS,sql用户名,部署,连接到其他工具所需的密码
· 将配置与代码分开存储在环境中
10M
var express = require(\‘express\‘)
var multer = require(\‘multer\‘)
var upload = multer({ dest: \‘uploads/\‘ })
var app = express()
app.post(\‘/profile\‘,
upload.single(\‘avatar\‘), function (req, res, next) {
// req.file is the `avatar` file
// req.body will hold the text fields, if there were any
})
app.post(\‘/photos/upload\‘,
upload.array(\‘photos\‘, 12), function (req, res, next) {
// req.files is array of `photos` files
// req.body will contain the text fields, if there were any
})
· 易于上传多部分/表单数据文件
92000
const axios = require(\‘axios\‘);
// Make a request for a user with a given ID
axios.get(\‘/user?ID=12345\‘)
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.finally(function () {
// always executed
});
· 从node.js发出HTTP请求
· 从浏览器发出XMLHttpRequests
· 支持Promise API
960万
var express = require(\‘express\‘)
var cors = require(\‘cors\‘)
var app = express()
app.use(cors())
app.get(\‘/products/:id\‘, function (req, res, next) {
res.json({msg: \‘This is CORS-enabled for all origins!\‘})
})
app.listen(80, function () {
console.log(\‘CORS-enabled web server listening on port 80\‘)
})
· 轻松处理CORS问题
370万
标签:yam mys use 部分 ejs bst ast als inf
原文地址:https://www.cnblogs.com/zhangycun/p/13570459.html