[英]Node.js 5.5.0 console.log won't log
I can't get any terminal output when I call console.log("anything") anywhere in my app. 当我在应用程序中的任何地方调用console.log(“ anything”)时,都无法获得任何终端输出。 The issue seems to have started when I updated node to 5.5.0, before that I had no issues.
当我将节点更新为5.5.0之前,该问题似乎已经开始,在此之前我没有任何问题。 What's going on?
这是怎么回事? I'm not sure what other information would be relevant.
我不确定还有哪些其他相关信息。 I'm running a standard Node.js http server with express.
我正在运行带有Express的标准Node.js http服务器。
Here is my server.js file. 这是我的server.js文件。 It's a little ugly right now...but in any case:
现在有点丑陋...但是无论如何:
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;
Here is my gruntfile.js (as mentioned in the comments): 这是我的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']);
};
Isolate you issue. 隔离您的问题。 94% of the time when you don't see console logs printing to the terminal it's due to to stdin and stdout of different processes.
94%的时间,您看不到控制台日志打印到终端,这是由于不同进程的stdin和stdout所致。
node server.js
. node server.js
。 If that works: nodemon server.js
. nodemon server.js
。 If that works: console-stamp
completely. console-stamp
。 If that doesn't fix it: concurrent
from the grunt file default and run nodemon
task directly in the chain. concurrent
并直接在链中运行nodemon
任务。 If that doesn't fix it:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.