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
Table of contents Prefab How to create a prefab T...
<br />I'm basically going crazy with thi...
First download the compressed version of mysql, t...
We implement a red image style for the clicked bu...
Problem Reproduction Alibaba Cloud Server, using ...
In actual projects, the up and down scroll bars a...
What is ssh Administrators can log in remotely to...
Table of contents Find the problem 1. How to remo...
This article example shares the specific code of ...
The span tag is often used when making HTML web pa...
This article shares the installation and configur...
Learned ConcurrentHashMap but don’t know how to a...
Achieve results Implementation Code html <div ...
Introduction to temporary tables What is a tempor...
The <canvas> element is designed for client...