Tuesday 30 May 2017

Can't access __dirname and process.cwd() in node.js

This may turn out to be a stupid question but I am struggling since past hour. In my following code when ever I try to log __dirname or process object, console prints nothing at all, plus it behaves weird (please see screenshot).

'use strict';
const http = require('http');
const url = require('url');
const querystring = require('querystring');

var createServerCallback = function (req,res) {

    var baseURI = url.parse(req.url);
    console.log(__dirname);
    console.log('hello world!');
    res.end("hello world");
};
http.createServer(createServerCallback).listen(3000,function () {
    console.log('listening on 3000');
    console.log(process.cwd() );
});

enter image description here



via SKG

No comments:

Post a Comment