当我在app中的任何地方调用console.log("任何")时,我无法获得任何终端输出。当我将节点更新到5.5.0之前,问题似乎已经开始,之前我没有任何问题。发生了什么事?我不确定其他相关信息是什么。我正在使用express。
运行标准的Node.js http服务器这是我的server.js文件。现在它有点难看......但无论如何:
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var passport = require('passport');
var flash = require('connect-flash');
var cors = require('cors');
var mongoose = require('mongoose');
var path = require('path');
var keys = require('./config/keys/apiKeys');
var morgan = require('morgan');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var validator = require('validator');
var fs = require('fs');
var ParseCloud = require('parse-cloud-express');
var Parse = ParseCloud.Parse;
require('console-stamp')(console, [])
var http = require('http').Server(app);
var https = require('https');
// config =========================================================================================
/*SSL */
var hskey = fs.readFileSync('./config/keys/theExperiment-key.pem');
var hscert = fs.readFileSync('./config/keys/theExperiment-cert.pem')
var options = {
key: hskey,
cert: hscert
};
var io = require('socket.io')(http);
var port = process.env.PORT || 8080;
app.use('/webhooks', ParseCloud.app);
require('./config/passport')(passport); //pass passport for configuration
app.use(bodyParser.json()); //get all data/stuff of the body (POST) parameters, parse application/json
app.use(bodyParser.json({type: 'application/vnd.api+json'})); //parse application/vnd.api+json as json
app.use(bodyParser.urlencoded({ extended: true })); //parse application/x-www-form-urlencoded
app.use(methodOverride("X-HTTP-Method-Override")); //override with the x-http-method-override header in the request. simulate delete/put
app.use(express.static(__dirname + '/public')); //set the static files location /public/img will be /img for users
//use template engine
app.set('views', __dirname + '/public/views/');
app.set('view engine', 'ejs');
//app.use(morgan('dev')); //log every request to the console
app.use(cookieParser()); //read cookies
//required for passport
app.use(session({
secret: "secret",
resave: true,
saveUninitialized: true
})); //session secret and defaults
app.use(passport.initialize());
app.use(passport.session()); //persistent login sessions
app.use(flash()); //use connect-flash for flash messages stored in session
app.use(cors()); //allow cross origin resource sharing
Parse.initialize(keys.parse.applicationId, keys.parse.javascriptKey, keys.parse.masterKey); //Init Parse
// routes ===========================================================================================
require('./app/routes')(app, passport, io); //configure our routes, pass in app and passport
// socketIO =========================================================================================
require('./app/sockets')(io,passport); //require socketio control
// start app ========================================================================================
http.listen(port);
console.log('Hello ' + port);
//expose app
exports = module.exports = app;
这是我的gruntfile.js(如评论中所述):
// Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
// JS TASKS ================================================================
// check all js files for errors
jshint: {
all: ['public/src/**/*.js']
},
// take all the js files and minify them into app.min.js
uglify: {
build: {
files: {
'public/dist/js/app.min.js': ['public/src/**/*.js', 'public/src/*.js']
}
}
},
// CSS TASKS ===============================================================
// process the less file to style.css
less: {
build: {
files: {
'public/dist/css/style.css': 'public/src/css/style.less'
}
}
},
//configure autoprefixing for compiled output css
autoprefixer: {
build: {
files: {
'public/dist/css/style.css': 'public/dist/css/style.css'
}
}
},
// take the processed style.css file and minify
cssmin: {
build: {
files: {
'public/dist/css/style.min.css': 'public/dist/css/style.css'
}
}
},
// COOL TASKS ==============================================================
// watch css and js files and process the above tasks
watch: {
css: {
files: ['public/src/css/**/*.less'],
tasks: ['less', 'autoprefixer', 'cssmin']
},
js: {
files: ['public/src/**/*.js'],
tasks: ['jshint', 'uglify']
}
},
// watch our node server for changes
nodemon: {
dev: {
script: 'server.js',
options: {
max_old_space_size: "2048"
}
}
},
// run watch and nodemon at the same time
concurrent: {
options: {
logConcurrentOutput: true
},
tasks: ['nodemon', 'watch']
},
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-nodemon');
grunt.loadNpmTasks('grunt-concurrent');
grunt.registerTask('default', ['less', 'autoprefixer', 'cssmin', 'jshint', 'uglify', 'concurrent']);
};
答案 0 :(得分:0)
隔离你的问题。有94%的时间没有看到控制台日志打印到终端,这是由于stdin和stdout不同的进程。
node server.js
。
如果有效:nodemon server.js
。
如果有效:console-stamp
。
如果这不能解决它:concurrent
并直接在链中运行nodemon
任务。
如果这不能解决它: