1

I am trying to use npm install debug in my node server.

var debugModule = require('debug');
var debugMainApp = debugModule('debugMainApp')

const express = require('express');

const app =  express();

const port ='3000';
const domain = 'localhost';

app.listen(port,domain,()=>{
     debugMainApp('Server started in port: ' + port + ' hostname: ' + domain);
});

debugMainApp('Server started in port: ' + port + ' hostname: ' + domain); is not printing anything to console.

My attempts to solve this issue
By setting the attribute debugMain.enabled = true manually debugMainApp('Server started in port: ' + port + ' hostname: ' + domain); printed the following into console:

mainApp Server started in port: 3000 hostname: localhost +0ms

To my understanding this debugMain.enabled attribute should be set automatically when an environment variable that matches the string debugModule('this_String') is set.

Here is how I set the environment variable and start my server

$ DEBUG=debugMainApp & node server.js

But it seems that the latter is not setting the environment variable properly.

Questions

  1. If you think my environment variable theory is right. What is the correct way to set an environment variable using a GitBash command line? e.g.$ DEBUG=mainApp & node server.js
  2. Could it be something else?

Thanks in advance.

More relevant info:
My OS: Windows 10
GitBash Version: 2.13.0.windows.1
NodeJS version: 6.10.3

RESOLUTION enter image description here

3
  • 1
    Can you try DEBUG=debugMain node server.js Commented Feb 19, 2018 at 20:32
  • when an environment variable that matches the string debugModule('this_String') is set. Yes, this string would be mainApp but you're calling it with debugMain. Commented Feb 19, 2018 at 20:33
  • It was a typo on my part, these strings DO match on my code. The '&' in $ DEBUG=debugMain & node server.js was messing things up. Commented Feb 19, 2018 at 20:43

1 Answer 1

2

The & would indicate to the bash to launch a process in background.

The right syntax is:

DEBUG=mainApp node server.js

See more at "Why is setting a variable before a command legal in bash?"

A simple command is a sequence of optional variable assignments followed by blank-separated words and redirections, and terminated by a control operator.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.