创建文件夹,在文件夹内再创建index.js
1.package.json
npm init -y
2.安装
npm install express ---save
3.index.js
//入口文件 // //1.加载express模块 var express=require('express'); //2.创建一个app对象(类似于创建一个server对象) var app=express(); //通过中间件监听指定路由请求 app.get('/index',function(req,res){ res.end('hello world'); }); //3.启动服务 app.listen(9092,function(){ console.log('http://localhost:9092'); })
启动
node index