Skip to content

ES6新语法特性总结,node.js的使用,npm的使用,日常总结

Notifications You must be signed in to change notification settings

Kelichao/node.ES6

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node.js

image

第一步

  • 生成一个package文件。把这个设置成app.js entry point: (app.js)

$ npm init

第二步

  • 安装express

$ npm install express --save

第三步

  • 在目录中新建app.js,填入以下代码
// 引入express模块
var express = require('express');
// 初始化express模块
var app = express();

app.get('/', function (req, res) {
  // 返回调用send方法进行输出
  res.send('Hello World!');
});

// 路由  /user 节点接受请求
// 地址为http://localhost:3000/user
app.get('/user', function (req, res) {
  res.send('user');
});

// 监听3000端口
var server = app.listen(3000, function () {
  var host = server.address().address;
  var port = server.address().port;

  console.log('Example app listening at http://%s:%s', host, port);
});

第四步

  • 运行命令,启动服务器

$ node app.js

然后在浏览器中打开 http://localhost:3000/ 并查看输出结果

image

About

ES6新语法特性总结,node.js的使用,npm的使用,日常总结

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published