当前位置:网站首页>[nodejs] nodejs create a simple server
[nodejs] nodejs create a simple server
2022-07-25 23:29:00 【Small_ xiuxiu】
Application Nodejs Create a simple application , First of all, we need to figure out a problem :
Nodejs What are the components of the application ?
1、require Instruction import Nodejs modular
2、 Create a server , Used to listen for requests from clients
3、 Modules that accept requests and respond to requests
The next step is to create a Nodejs application
1、 introduce require modular
//server.js
var http = require('http');
2、 Create a server
A HTTP Server and listen 8000 port
//server.js
http.createServer(function(request,response) {
// something to response
}).listen(8000);
3、 Accept requests and respond to requests
The response header and response content are set here , When the client accesses localhost:8000 When , The server will receive the request and return the response Back end service created successfully .
//server.js
http.createServer(function(request,response) {
response.writeHead(200,{
'Content-Type': 'text/plain;charset=utf-8'});
response.end(JSON.parse(JSON.stringify(' Back end service created successfully ')));
}).listen(8000);
Last , perform node command node server.js You can start it http The server .
Here's the picture :
such , One Nodejs Simple app created successfully .
边栏推荐
- Scaffold installation
- R language drawing parameters (R language plot drawing)
- Wrote a little webapi knowledge points from 0 to 1
- initializer_list工具库学习
- 策略模式_
- Custom MVC principle
- Npm+ module loading mechanism
- Anaconda installation tutorial environment variables (how to configure environment variables)
- Simulate and implement common interfaces of string class
- POI特效 市场调研
猜你喜欢

Learning exploration - waves

POI special effects Market Research

Apple CMS V10 template /mxone Pro adaptive film and television website template

Idea sets get and set templates to solve the naming problem of boolean type fields

chown: changing ownership of ‘/var/lib/mysql/‘: Operation not permitted

图的遍历-DFS,BFS(代码详解)

类和对象(2)(6个默认成员函数)

XXE&XML-外部实体注入-利用和绕过

npm+模块加载机制

Firewall command simple operation
随机推荐
Rendering, filtering (filtering) and sorting of lists
数组中重复的数字
Summary of common PHP functions
@Autowired注解 required属性
物理防火墙是什么?有什么作用?
utility实用组件学习之swap,move,forward,exchange
Implementation of date class
Which securities company should a novice choose to open an account? Is it safe?
762. Prime number calculation setting in binary representation
Data broker understanding
Classes and objects (2) (6 default member functions)
ETL tool (data synchronization) II
@Import
在应用中使用 Jetpack 库
Regular expression (user name form verification / verification of landline number / regular replacement)
TS class
学习探索-波浪
General paging function
[wechat applet] page navigation
[code case] blog page design (with complete source code)