当前位置:网站首页>Start from scratch - Web Host - 01
Start from scratch - Web Host - 01
2022-07-02 02:10:00 【L Jianhao 忄 YH】
Starting from scratch - Web host - 01
Preface :
- I went to work as a social animal immediately after the winter vacation , The first project received after work is to make a local host computer into a web version . The local upper computer uses
C++
andQt
Library , I have used it beforePython
andQt
Library writing host computer , It is used to receive the image data of the single chip microcomputer camera . I originally wanted to do the whole tutorial , I was too lazy to do , I don't want to do it now . The source code is in myGitHub
In the warehouse , Those who are interested can copy and run :【 Portal 】.- Now I plan to use
JavaScript
Write a web version of the upper computer , Because I have a little experience before . This has been a tutorial :【 be based on Node.js And WebSocket Set up server note - 00 - Initial cloud server 】. This time the whole thing is a little complete , Because when I did it before, I actually knew a little ,js Not familiar with language . Although not very familiar now , But writing simple code is still useful . Record the learning process .
One 、 Environment building
First of all, think about how this web page Deploy ( I don't know whether this term is right ), There are many options , I have used two , One is to use.pyhton
, One is to useJavaScript
pyhton You can refer to this tutorial for the relevant implementation methods of :【 How to make a web page for your girlfriend as a birthday gift 】, Not the point I want to introduce , skip.
I wanted to explain
node.js
andjs
, such as :js The code can also be directly allowed in the browser console , No installation required nodejs…… As soon as I write, I feel embarrassed 、 the language fails to express the meaning , Change and give up . I'd better put other people's popular science articles directly :【 Portal 】. I am responsible for recording the process .
1、 install Node.js
Recommended tutorials :【Nodejs+npm Detailed installation _Gilagamesh The blog of -CSDN Blog _node install npm】
- Download installation package ;【 download | Node.js Chinese net (nodejs.cn)】
- Install the software ; next step … Installation address … next step … complete .
- Install the module manager npm; Integrated , Default installation .
Default address :C:\Users\ user name \AppData\Roaming\npm
- Check and configure environment variables ; My computer - attribute - Advanced system setup - environment variable .
node -v
npm -v
- modify npm Cache directory and global directory path ;( Create new folders without )
npm config set prefix "node The installation path \node_global" // Configuration path
npm config set cache "node The installation path \node_cache" //
npm config get prefix // View path
npm config get cache //
- To configure npm and nodejs Environment variables of ;
Variable name :NODE_PATH
A variable's value :node The installation path \node_global\node_modules
- In fact, the global module is generally not installed , Are installed in the project . So this path is rarely used .
2、 New project
- New project folder , Open the terminal in this folder path , Enter the following command . The module package management script can be initialized
package-lock.json
.
npm install
- Consider what to use Web frame , I've used
koa
、nodejs-websocket
, The following is the tutorial used before .
【koa introduction - Liao Xuefeng's official website (liaoxuefeng.com)】
- At present, it is recommended that
Express
frame (Because I just saw), Use npm InstallExpress
modular .
npm install express --save
【Node.js Express frame | Novice tutorial (runoob.com)】
【Express Use of framework ( detailed )_ The imprint of rain blog -CSDN Blog _express Frame usage 】
- Create a few more folders , Deposit html、css、js、 Pictures and other documents . The project catalogue refers to :【 How to make a web page for your girlfriend as a birthday gift 】
|-- project
| – node_modules // Module package
| – static // Static files
| | – css // css file
| | – image // Picture file
| | — script // js file
| – templates // html file
| – package-lock.json // Module package registry
- It may be crap More , Here is formal Start .
Two 、 mount
Code reference :【Express in app.use() usage - Simple books (jianshu.com)】
- In the project root directory
project
Create a script under ,express.js
. Put it in the root directory for convenient direct access to local static files . Enter the following code in the script .
// express.js file
let express = require('express');
let app = express();
// Direct access to local static files
app.use('/',express.static('./'));
// mount
let server = app.listen(8080, function ()
{
let port = server.address().port;
console.log(" visit :http://localhost:%s/templates/main.html",port);
})
- Then in the project directory
project/templates
Create web page file under ,main.html
. You can enter some words in the web page .
<!-- main.html file -->
test
function
express.js
Script files , Then click the website printed out in the terminal , You can open the web page and see “ test ” Two words .thus , The web page has been mounted . Then deploy the cloud , Set domain name and other knowledge , You can refer to another tutorial :【 be based on Node.js And WebSocket Set up server note - 00 - Initial cloud server _Lovely_him The blog of -CSDN Blog _nodejs websocket The server 】. This part is not the focus of this course , The key is The process of making web pages and Use of serial port function .
3、 ... and 、 Layout of web pages
Leave a hole , Waiting for update .
边栏推荐
- Logging only errors to the console Set system property ‘log4j2. debug‘ to sh
- 剑指 Offer 42. 连续子数组的最大和
- 自动浏览拼多多商品
- If you want to rewind the video picture, what simple methods can you use?
- Is the knowledge of University useless and outdated?
- [技术发展-21]:网络与通信技术的应用与发展快速概览-1- 互联网网络技术
- Ar Augmented Reality applicable scenarios
- golang---锁
- leetcode2309. The best English letters with both upper and lower case (simple, weekly)
- Sword finger offer 31 Stack push in and pop-up sequence
猜你喜欢
RTL8189FS如何关闭Debug信息
A quick understanding of digital electricity
From January 11, 2007 to January 11, 2022, I have been in SAP Chengdu Research Institute for 15 years
【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享
The wave of layoffs in big factories continues, but I, who was born in both non undergraduate schools, turned against the wind and entered Alibaba
How to debug apps remotely and online?
剑指 Offer 62. 圆圈中最后剩下的数字
Word search applet design report based on cloud development +ppt+ project source code + demonstration video
Discussion on the idea of platform construction
JMeter (II) - install the custom thread groups plug-in
随机推荐
How to debug apps remotely and online?
SQL server calculates the daily average and annual average of the whole province
The wave of layoffs in big factories continues, but I, who was born in both non undergraduate schools, turned against the wind and entered Alibaba
An analysis of circuit for quick understanding
【LeetCode 43】236. The nearest common ancestor of binary tree
Niuke - Huawei question bank (51~60)
If you want to rewind the video picture, what simple methods can you use?
2022 Q2 - 提昇技能的技巧總結
How to use redis ordered collection
A quick understanding of analog electricity
如何用一款产品推动「品牌的惊险一跃」?
The concepts and differences between MySQL stored procedures and stored functions, as well as how to create them, the role of delimiter, the viewing, modification, deletion of stored procedures and fu
MySQL如何解决delete大量数据后空间不释放的问题
MySQL主从延迟问题怎么解决
Spend a week painstakingly sorting out the interview questions and answers of high-frequency software testing / automated testing
Ar Augmented Reality applicable scenarios
leetcode373. Find and minimum k-pair numbers (medium)
CSDN insertion directory in 1 second
【毕业季】研究生学长分享怎样让本科更有意义
剑指 Offer II 031. 最近最少使用缓存