Search code examples
javascriptnode.jsexpressgulpnodemon

Error '\"node .\bin\www\"' is not recognized as an internal or external command, operable program or batch file with gulp


Hi I am using gulp and nodemon utility to automate my build process. It was working before I manually debug my application using vscode. I don't want to debug it now, want to run it simply.

I am running this command to start gulp and automate build if any changes in JS files but I am getting an error.

I checked some threads where it is suggested to use set DEBUG=express:* & node bin/www and it is working. I don't want to do this, don't know what it does. I wanna use gulp.

$ gulp
[18:11:31] Using gulpfile D:\api\gulpfile.js
[18:11:31] Starting 'default'...
[18:11:31] Finished 'default' after 101 ms
[18:11:31] [nodemon] 1.12.0
[18:11:31] [nodemon] to restart at any time, enter `rs`
[18:11:31] [nodemon] watching: *.*
[18:11:31] [nodemon] starting `node ./bin/www`
'\"node .\bin\www\"' is not recognized as an internal or external command,
operable program or batch file.
[18:11:31] [nodemon] app crashed - waiting for file changes before starting...

gulpfile.js

const gulp = require("gulp"),
  nodemon = require("gulp-nodemon");

gulp.task("default", () => {
  nodemon({ ext: "js" });
});

www

#!/usr/bin/env node

/**
 * Module dependencies.
 */

var app = require('../app');
var debug = require('debug')('cryptocurrency-api:server');
var http = require('http');

/**
 * Get port from environment and store in Express.
 */

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
 * Create HTTP server.
 */

var server = http.createServer(app);

/**
 * Listen on provided port, on all network interfaces.
 */

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
 * Normalize a port into a number, string, or false.
 */

function normalizePort(val) {
  var port = parseInt(val, 10);

  if (isNaN(port)) {
    // named pipe
    return val;
  }

  if (port >= 0) {
    // port number
    return port;
  }

  return false;
}

/**
 * Event listener for HTTP server "error" event.
 */

function onError(error) {
  if (error.syscall !== 'listen') {
    throw error;
  }

  var bind = typeof port === 'string'
    ? 'Pipe ' + port
    : 'Port ' + port;

  // handle specific listen errors with friendly messages
  switch (error.code) {
    case 'EACCES':
      console.error(bind + ' requires elevated privileges');
      process.exit(1);
      break;
    case 'EADDRINUSE':
      console.error(bind + ' is already in use');
      process.exit(1);
      break;
    default:
      throw error;
  }
}

/**
 * Event listener for HTTP server "listening" event.
 */

function onListening() {
  var addr = server.address();
  var bind = typeof addr === 'string'
    ? 'pipe ' + addr
    : 'port ' + addr.port;
  debug('Listening on ' + bind);
}

Solution

  • Probably something is corrupted with nodemon version 1.12.0.
    Had the same problem and solved it by removing and reinstalling an older version.

    Remove nodemon using:
    yarn global remove nodemon

    And then reinstall - this time specifying an older version
    yarn global install nodemon@1.11.0