标签:data 配置 下载 ref 原因 引入 log nodejs family
{ "cmd": ["node", "$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "working_dir": "${project_path:${folder}}", "selector": "source.js", "shell": true, "encoding": "utf-8", "windows": { "cmd": ["node", "$file"] } }
const http = require(‘http‘); let server = http.createServer(function(request, response){ console.log(req.url); switch(req.url) { case ‘1.html‘: res.write(‘1111‘); break; case ‘2.html‘: res.write(‘2222‘); break; default: res.write(‘404‘); break; }; console.log(‘被请求了‘); // res.write(); res.end(); }); server.listen(9090);
const fs = require(‘fs‘); fs.readFile(‘1.txt‘, function(err, data){ if(err) { console.log(‘读取失败‘); }else { console.log(data.toString()); } });
const fs = require(‘fs‘); fs.writeFile(‘1.txt‘, ‘jason is a hero!‘, function(err){ console.log(err); });
// 引入http模块 const http = require(‘http‘); // 引入fs模块 const fs = require(‘fs‘); // 创建一个连接 let server = http.createServer( (req, res) => { // 指定静态资源 let file_name = ‘./www‘ + req.url; fs.readFile(file_name, (err, data) => { if(err) { res.write(‘404‘); } else { res.write(data); } res.end(); }); // res.end(); }); // 监听端口 server.listen(9888);
nodejs学习笔记一( sublime、atom开发环境,http模块,fs模块的初识)
标签:data 配置 下载 ref 原因 引入 log nodejs family
原文地址:http://www.cnblogs.com/jasonwang2y60/p/7056908.html