nodejs: express basic

Posted Nyan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nodejs: express basic相关的知识,希望对你有一定的参考价值。

express: web application framework

第一个express 基本应用:

const express = require(‘express‘);
const port = 3000;

const app = express();

app.use((req, res) => {
    res.json("hello express")
});

app.get(‘/users/:id‘, (req, res) => {
    const { id } = req.params;
    res.json({
        id,
        name: "Nyan Shen"
    })
})

app.listen(port, () => {
    console.log(`server starded listening at http://localhost:${port}`)
})

/**
let http = require(‘http‘);

let server = http.createServer((req, res) => {
    res.end("hello server test")
});

server.listen(3000, ‘127.0.0.1‘, () => {
    console.log(‘server started...‘)
})
*/

遇到问题:Client does not support authentication protocol requested by server; consider upgrading mysql client

解决问题:

use mysql;
alter user ‘root‘@‘localhost‘ identified with mysql_native_password by ‘数据库密码‘;
flush privileges;

 

以上是关于nodejs: express basic的主要内容,如果未能解决你的问题,请参考以下文章

text Visual Basic代码片段

nodejs 怎么全局安装express

nodejs可以自定义header吗

nodeJs express

nodejs常用代码片段

Nodejs / Express - 启动我的应用程序:不推荐使用 express.createServer()