当前位置:网站首页>Quickly master nodejs installation and getting started
Quickly master nodejs installation and getting started
2022-07-29 02:32:00 【Mighty CRUD】
One 、Nodejs
1.1、Nodejs Introduce
Official website :http://nodejs.cn/
Node It is a let. JavaScript Development platform running on the server , It makes JavaScript Become and PHP、Python、Perl、Ruby Wait for the server-side language to be equal to the script language . Published on 2009 year 5 month , from Ryan Dahl Development , The essence is right. Chrome V8 The engine is packaged .
To put it simply Node.js It's running on the server side JavaScript. Node.js It's based on Chrome JavaScript A platform built at runtime . The underlying architecture is :javascript. file extension :.js
Node.js It's an event driven I/O Server side JavaScript Environmental Science , be based on Google Of V8 engine ,V8 The engine performs Javascript Very fast , Very good performance .

Download the corresponding to your system Node.js edition :
Download address :https://nodejs.org/zh-cn/download
Help document :https://nodejs.org/zh-cn/docs
About Nodejs:https://nodejs.org/zh-cn/about
1.2、 install
Open... After downloading The next step of mindless installation The default installation is enough 
After the installation is completed, check whether the installation is successful :
node -v

1.3、 Summary
Nodejs It's a computer language , Running in the system v8(jvm) In the engine . The file suffix is js The command to run is :node
Two 、Nodejs Quick start
2.1、 Quick start -Hello World
1、 Create folder nodejs
2、 establish helloworld.js
Be similar to java Medium System.out.println("")
console.log('Hello World!!!')
function :node helloworld.js
result :hello world!!!
3、 Open command line terminal :Ctrl + Shift + y
The browser kernel consists of two parts :
DOM Rendering engine ;
- java script Parser (js engine )
- js Running in the browser kernel js Inside the engine
4、 Summary
Node.js It runs out of the browser environment JavaScript Program , be based on V8 engine
2.2、Node - Implement request response
1、 establish httpserver.js ;
// The import module is require Is similar to the import java.io
const http = require('http');
// 1: Create a httpserver service
http.createServer(function(request,response){
// How do browsers know hello server!!!
response.writeHead(200,{
'Content-type':'text/plain'}); // The meaning of this sentence is : Tell the browser that it will
// With text-plain Parse hello server This data .
// Output content to the browser
response.end("<strong>hello server!!!</strong>");
}).listen(8888);
console.log(" The service you started is :http://localhpst:8888 To start successfully !!");
// 2: Monitor one port 8888
// 3: Start the running service node httpserver.js
// 4: Access in browser http://localhost:8888
2、 Run the server program ;
node httpserver.js
3、 After the server starts successfully , Enter... In the browser :http://localhost:8888/ see webserver Running successfully , And the output html page
4、 Out of Service :ctrl + c
2.3、Node- operation MYSQL database
Reference resources :https://www.npmjs.com/package/mysql
1: install mysql rely on
npm install mysql
2: Definition db.js To operate
//1: Import mysql Dependency package , mysql A module belonging to a third party is similar to java.sql The same thing
var mysql = require("mysql");
// 1: Create a mysql Of Connection object
// 2: Configure data connection information
var connection =mysql.createConnection({
host:"127.0.0.1",
port:3306,
user:"root",
password:"mkxiaoer",
database:"testdb"
});
// 3: Open up connections
connection.connect();
// 4: perform curd
connection.query("select * from user",function(error,results,fields){
// If the query fails , Direct selling
if(error)throw error;
// The query is successful
console.log("results = ",results);
});
// 5: Close the connection
connection.end();
// The last step : function node db.js See the effect
3: New database :db_test And table kss_user surface
/*
Navicat MySQL Data Transfer
Source Server : localhost
Source Server Type : MySQL
Source Server Version : 60011
Source Host : localhost:3306
Source Schema : testdb
Target Server Type : MySQL
Target Server Version : 60011
File Encoding : 65001
Date: 20/01/2021 21:38:55
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of kss_user
-- ----------------------------
INSERT INTO `user` VALUES (1, ' Zhang San ');
INSERT INTO `user` VALUES (2, ' Li Si ');
SET FOREIGN_KEY_CHECKS = 1;
4、 function db.js
node db
If you want to develop more complex software based on Node.js The application background , Need to learn more Node.js Of Web Develop related frameworks express,art-template、koa etc.
边栏推荐
- 深度剖析 —— 预处理
- 3D intelligent factory process flow visualization interactive display application advantages
- Kubesphere multi node installation
- MySQL和Redis的双写一致性
- 密码安全如何保障?安全浏览器如何管理密码?
- 会议OA之会议通知
- 连PostgreSQL问题:expected authentication request from server, but received v
- ES6事件绑定(v-on用法)
- Talk about 11 tips for interface performance optimization
- 一文理解分布式开发中的服务治理
猜你喜欢

MQTT例程

详解异步任务:任务的状态及生命周期管理

What if there is not enough time for adequate testing?

C语言实现三子棋游戏

Installation guide for proftpd Secure FTP server with TLS encryption enabled

Day 15 (VLAN related knowledge)

发布融资需求1.29亿元,大科城项目路演持续浇灌科创“好苗子”

快速掌握Nodejs安装以及入门

响应式织梦模板酒店客房类网站

Exploration and practice of network security vulnerability management
随机推荐
Responsive dream weaving template outdoor camping website
Branch management practice of "two pizza" team
进程间通信---对管道的详细讲解(图文案例讲解)
千万不要把Request传递到异步线程里面,有坑
How to guarantee password security? How does the secure browser manage passwords?
快速掌握Nodejs安装以及入门
[upload picture 2-cropable]
详解JS的四种异步解决方案:回调函数、Promise、Generator、async/await
6年测试经验,教大家测试~如何把控项目
聊聊接口性能优化的11个小技巧
Responsive dream weaving template home decoration building materials website
3种过期策略
线上3d数字展厅制作方案及优点
TCP重传机制有哪些?
NPM install reports an error: eperm: operation not permitted, rename
Ten methods to prevent blackmail software from attacking data
我被这个浏览了 746000 次的问题惊住了
4年测试经验,好不容易进了阿里,两个月后我选择了裸辞...
Explain the four asynchronous solutions of JS in detail: callback function, promise, generator, async/await
PS + PL heterogeneous multicore case development manual for Ti C6000 tms320c6678 DSP + zynq-7045 (2)