nodejs和gulp一起使用碰到的问题?
var gulp = require('gulp');
var child = require('child_process');
var express = require('express');
var app = express();
//......
app.use(express.static('public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/', function (req, res) {
//......
});
//此处我想当post时,执行默认的gulp task,但是出现了错误,错误如下
app.post("/", function(req, res){
//.....
child.exec('gulp', function(err){
if(err)
console.log(err);
});
});
var server = app.listen(3000, function (req, res){
console.log("程序正在运行......");
// gulp.start('default');
});
node app.js文件后,错误如下:
{ [Error: Command failed: /bin/sh -c gulp
events.js:141
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3000
at Object.exports._errnoException (util.js:837:11)
at exports._exceptionWithHostPort (util.js:860:20)
at Server._listen2 (net.js:1231:14)
at listen (net.js:1267:10)
at Server.listen (net.js:1363:5)
at EventEmitter.listen (/home/quoniam/nodeStudy/gulp-musheng/node_modules/express/lib/application.js:617:24)
at Object.<anonymous> (/home/quoniam/nodeStudy/gulp-musheng/gulpfile.js:49:18)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
] killed: false, code: 1, signal: null, cmd: '/bin/sh -c gulp' }
我想问一下这个问题怎么解决?(问题:我想当post时,执行默认的gulp task,但是出现了错误)
1 回复
应该是 child.exec(‘gulp taskName’); child.stdot.on(‘data’, function(data){ conosle.log(data); }) 我是这样写的