A simplest node, express and mysql demo
-
Create Mysql database with table user
table definition:
id: int
user_name: varchar(50๏ผ
password: varch(50)insert a new record into table user
{"id":1,
"user_name":"admin",
"password":"admin"} -
User mysql user sa, password 123456
-
Create express project by
express node_mysql_demo
cd express
npm install
npm install mysql -
Create folder db
-
Create db config file config.js
-
Create db control file db.js
-
Update routes/index.js, to use api/v1.js
-
Create api v1 folder under folder routes
-
Create v1.js under folder routes/api/
-
Start the server by
npm start -
Check result by opening this link in browser
http://localhost:3000/api/v1/users/1this is the result from res.json()