Coder Social home page Coder Social logo

Comments (14)

AndrewKeig avatar AndrewKeig commented on September 23, 2024

Hi

You need a config/test.json file:

{
"express": {
"port": 3000
},
"logger" : {
"filename": "logs/run.log",
"level": "silly"
}
}

from advanced-express-application-development.

alsoicode avatar alsoicode commented on September 23, 2024

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.

AndrewKeig avatar AndrewKeig commented on September 23, 2024

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.

alsoicode avatar alsoicode commented on September 23, 2024

Ok, my progress so far is at: https://github.com/alsoicode/vision

from advanced-express-application-development.

AndrewKeig avatar AndrewKeig commented on September 23, 2024

Hopefully this should also resolve. Let me know if you still have a problem.

from advanced-express-application-development.

alsoicode avatar alsoicode commented on September 23, 2024

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.

AndrewKeig avatar AndrewKeig commented on September 23, 2024

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.

alsoicode avatar alsoicode commented on September 23, 2024

I get:

filename undefined

from the console.log() statement

from advanced-express-application-development.

AndrewKeig avatar AndrewKeig commented on September 23, 2024

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.

alsoicode avatar alsoicode commented on September 23, 2024

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.

AndrewKeig avatar AndrewKeig commented on September 23, 2024

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.

alsoicode avatar alsoicode commented on September 23, 2024

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.

AndrewKeig avatar AndrewKeig commented on September 23, 2024

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.

alsoicode avatar alsoicode commented on September 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.