node.js
来源:互联网 发布:初级php开发工程师 编辑:程序博客网 时间:2024/06/15 12:38
// 创建服务器
//路由
// 引入http模块,里面封装了又创建服务器的方法
var http = require('http');
// createServer创建服务器,把服务器返回给我们
// 参数是一个回调函数:
var server = http.createServer(function(req,res) {
//code
res.writeHead(200,{'Content-type':'text/plain;charset=utf-8'});
res.write('<h1>张猛</h1>');
// end表明结束,必须的有
res.end();
});
// 给服务器设置路径,端口等,
// 第一个参数:端口,第二个参数:路径,第三个参数:回调函数,检测服务器是否启动成功
//如果启动失败,会把失败信息给我们err
server.listen(8888,'localhost',function(err) {
// 根据是否返回了失败信息确定是否启动成功
if (err) {
console.log(err);
} else {
console.log('服务器启动成功');
}
})
// 吧crateServer和liston连在一起
// http.createServer(function (req,res) {
//
// }).listen(8888);
// express模块,对http做的更深层次的封装
//路由
// 引入http模块,里面封装了又创建服务器的方法
var http = require('http');
// createServer创建服务器,把服务器返回给我们
// 参数是一个回调函数:
var server = http.createServer(function(req,res) {
//code
res.writeHead(200,{'Content-type':'text/plain;charset=utf-8'});
res.write('<h1>张猛</h1>');
// end表明结束,必须的有
res.end();
});
// 给服务器设置路径,端口等,
// 第一个参数:端口,第二个参数:路径,第三个参数:回调函数,检测服务器是否启动成功
//如果启动失败,会把失败信息给我们err
server.listen(8888,'localhost',function(err) {
// 根据是否返回了失败信息确定是否启动成功
if (err) {
console.log(err);
} else {
console.log('服务器启动成功');
}
})
// 吧crateServer和liston连在一起
// http.createServer(function (req,res) {
//
// }).listen(8888);
// express模块,对http做的更深层次的封装
//npm :他是node里面管理各个模块的
var express = require('express');
var app = express();
app.get('*',function (req,res) {
res.sendFile(__dirname+req.url);
})
app.listen(8888,'localhost',function (err) {
if (err) {
console.log(err);
} else {
console.log('服务器启动成功');
}
});
命令:
node —>server.js
npm install express 安装express 模块
cd 进入目录;
cd.. 返回上级目录;
del 删除文件
dir 列出文件列表;
cls 清屏
0 0
- js node
- Node.JS:
- node js
- node.js
- node.js
- node.js
- Node.js
- node.js
- Node.js
- Node.Js
- node js
- Node.js
- node.js
- node.js
- node.js
- node.js
- node.js
- node.js
- Java Web 初级程序员 -第6天学习内容:this,final,instance of
- AndroidStudio_常用快捷键_新手_精简版
- JAVA中的并发工具类(一)----控制并发数的Semaphore
- 《Windows核心编程》之“Windows挂钩”(二)
- Linux 信号
- node.js
- 开发者所需要知道的 iOS 10 SDK 新特性
- BZOJ1593: [Usaco2008 Feb]Hotel 旅馆 线段树
- gsoap入门:获取gsoap的错误信息
- db2安装完后,在/home/db2inst1/sqllib/include/目录下没有db2ApiDf.h等API头文件的问题
- 发送邮件的plsql代码(续)
- applet中archive?
- 微信支付
- UVa12169 - Disgruntled Judge(模运算、拓展欧几里得)