Comments (14)
Hi
You need a config/test.json file:
{
"express": {
"port": 3000
},
"logger" : {
"filename": "logs/run.log",
"level": "silly"
}
}
from advanced-express-application-development.
Hi Andrew,
Thanks for the reply. I actually do have config/test.json as specified.
My directory structure is:
vision/
config/
coverage.json
default.json
development.json
test.json
from advanced-express-application-development.
Cool; the only way I could replicate the error was with this in the config file:
As you can see the filename is empty; this throws the same error.
Can you setup a repo for this so I can take a look.
{
"express": {
"port": 3000
},
"logger" : {
"filename": "",
"level": "silly"
}
}
from advanced-express-application-development.
Ok, my progress so far is at: https://github.com/alsoicode/vision
from advanced-express-application-development.
Hopefully this should also resolve. Let me know if you still have a problem.
from advanced-express-application-development.
Hmm. Running:
mocha test
will work just fine, but I still get the same error from Grunt. Is it not able to fund the log file or something?
from advanced-express-application-development.
Lets see what the console.log says; let me know if anything comes through. I will test this on linux later.
Try this in ../logger/index.js to print out the file path
var winston = require('winston'),
config = require('../configuration');
function Logger() {
console.log('filename', config.get("logger:filename"));
return winston.add(winston.transports.File, {
filename: config.get("logger:filename"),
maxsize: 1048576,
maxFiles: 3,
level: config.get("logger:level")
});
}
module.exports = new Logger();
For now you can simply switch on the console logger; replace ../logger/index.js like so:
function Logger() {
return winston;
}
module.exports = new Logger();
from advanced-express-application-development.
I get:
filename undefined
from the console.log()
statement
from advanced-express-application-development.
It seems config.get is returning undefined; which means we cannot find the item "logger:filename" inside config. I would suggest replacing the ./lib/configuration/index.js with this; let me know what values you get for environment/key.
var nconf = require('nconf');
function Config() {
nconf.argv().env('_');
var environment = nconf.get('NODE:ENV') || 'development';
console.log("environment: ", environment);
nconf.file(environment, 'config/' + environment + '.json');
nconf.file('default', 'config/default.json');
}
Config.prototype.get = function(key) {
console.log("key: ", key);
return nconf.get(key);
}
module.exports = new Config();
from advanced-express-application-development.
Finally figured out what the problem was. environment
is returned as uppercase: "TEST", so when the logger tries to open config/TEST.json
, it's not there, but config/test.json
is.
So, I just changed the environment to be returned as lower case:
var nconf = require('nconf');
function Config() {
nconf.argv().env('_');
var environment = nconf.get('NODE:ENV').toLowerCase() || 'development';
nconf.file(environment, 'config/' + environment + '.json');
nconf.file('default', 'config/default.json');
}
and now:
$ mocha test
will pass :) Yeah!
from advanced-express-application-development.
There is no need to make this change; why have you called the file TEST.json; its very clear in the book on page 13;
"Now add the following configuration to the development, test, and coverage config files: ./config/development.json, ./config/test.json, and ./config/ coverage.json."
from advanced-express-application-development.
Hi,
Actually, it's the other way around. I named the file test.json - lowercase, but the environment variable was coming back uppercase for me, hence the need to take it to lower case in order to find the file. I'm triple-checking my code against the book, and trying to be very careful to follow the examples to the letter.
If you look at my source code, you'll see that the file is named lowercase as well.
Brandon
On Wed, Jan 29, 2014 at 4:29 PM, Andrew Keig [email protected]:
There is no need to make this change; why have you called the file
TEST.json; its very clear in the book on page 13;Now add the following configuration to the development, test, and coverage
config files: ./config/development.json, ./config/test.json, and ./config/
coverage.json.Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-33632929
.
from advanced-express-application-development.
Hi Brandon
Apologies; you are right; Linux is not so forgiving on filenames; which is why it passed on my mac.
If you would like to contribute a fix; please do.
from advanced-express-application-development.
No worries at all. By the way, I revised my review on Amazon to be more constructive, so my apologies for getting frustrated as well. I gave you 4 stars; it's a well written book. I'm primarily a Python developer, so JavaScript isn't my strongest suit, and I tend to not have as much patience with it, or even know where to look for problems sometimes, but I'm very anxious to learn more, which is why I bought your book.
from advanced-express-application-development.
Related Issues (9)
- Chapter 2 tests no change (just Github token updated) 22 passed but 2 tests failed. HOT 1
- CH 2, Mongoose returning different object structure
- grunt coverage is not working with latest devDependencies HOT 1
- Chapter 2 Tests failing with TypeError: Cannot call method 'drop' of undefined HOT 6
- Trouble "Authorising App" in Chapter 5 page 93. HOT 1
- Question not issue HOT 1
- Github Commits - Fatal error: Cannot convert null to object HOT 3
- Discrepancies between the book and the repo HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from advanced-express-application-development.