1. First install node, express, express-generator (the 4.x version separates the generator so it needs to be installed separately) 2. Enter the project file and enter the command I usually rewrite app.js and then delete the bin file, because the simpler the better. var http = require('http') var server = http.createServer(app) //Omit the middle and then delete the direct listening in the final export app server.listen('3030',()=>{console.log('Server started successfully');}) Finally, modify package.json. Due to everyone's habits, I am used to enabling the dev startup in the scripts. "scripts": { "dev": "nodemon ./app.js" },
2. Install the mysql database Then test it in the index I won’t talk about the detailed database operations. 3. The following is the secondary encapsulation of routing
//This is to handle the execution of database statements const { exec } = require('../unil/db') /* GET home page. */ init=(req,res)=>{ exec('select * from goods_type_info where 1=1', [], (err, result) => { if (err) { console.log('Service link error'); } else { res.send({code:200000,data:result}) } }) } module.exports = {init}; //Then call it in the required file let getDate=require('../app/index') /* GET home page. */ router.get('/',getDate.init); //Which route executes which statement? This is the first one to process the route. The second one is the method of route execution. If the route is nested, it needs to be spliced.
Here, the front end remembers that the request header initiated is in this format, otherwise there will be problems with the data format received on the back end. Different formats have different writing methods. For details, see Baidu In this way, you can quickly build a simple background framework Here I would like to add a problem I encountered. If you build it locally, you must write the port number when opening the front end, otherwise it is easy to cause false cross-domain, causing the front end to request, the back end to save data, and you cannot get the session when you request the second time. This is the end of this article about node quick background construction. For more relevant node quick background construction content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: The Complete List of MIME Types
>>: Html tips to make your code semantic
A few days ago, I saw an example written by @Kyle...
1. Introduction to TypeScript The previous articl...
Stored Functions What is a stored function: It en...
Preface: I encountered a requirement to extract s...
This article uses examples to illustrate the prin...
1. display:box; Setting this property on an eleme...
1. Download the axios plugin cnpm install axios -...
Table of contents Preface introduce 1. Mechanism ...
Table of contents 1. Prototype chain inheritance ...
First, let me explain the version of MySQL: mysql...
Table of contents Problem description: Cause Anal...
Preface Execute the show create table <tablena...
I encountered this problem today. I reassigned the...
Hello everyone, I am Qiufeng. Recently, WeChat ha...
Preface After MySQL version 3.23.44, InnoDB engin...