How can run app using Express 4 without "DEBUG=node:* ./bin/www" How can run app using Express 4 without "DEBUG=node:* ./bin/www" express express

How can run app using Express 4 without "DEBUG=node:* ./bin/www"


First off I think it is important to understand that an Express app in nothing more than an initiated Express app object which is listening on some port (see ex1). On the first line of this example you can see what is called a linux hashbang or shebang which is a line that tells your shell what kind of interpreter it should use to execute the following file. Therefore it is possible to create a file with the node hashbang, remove the .js extension en still be able to execute it using ./{myscript} where ./ causes it to run.

Now that we got the basics down I am fairly certain you used the express-generator to create your app. Which indeed tells you to run your app using the DEBUG=node:* ./bin/www. The ./bin/www/ simply runs the www file in the /bin folder. Which is essentially a javascript file with a node hashbang that imports the app instance from app.js and initiates and http server on it, which start listening for events. The DEBUG={name}:* command is used by npm debug npm debug link. It simply tells the package which debug functions it should use. The * being a wildcard for: use all of them all (see npm debug package docs for for info).

#!/usr/bin/env nodevar express = require('express')var app = express()app.get(function(req, res) {    res.send('Hello')})app.listen(8080, function(){    console.log('Server started on port:8080')})

Tip if you simply dont like typing the command because it's too long I suggest you to add it to the scripts section in your package.json.

'scripts': {    'start': 'DEBUG=node:* ./bin/www'}

You can then run it by using npm start


If someone will have teh same problem as I, I'm posting answer I found:

./bin/www - is linux executable file that incapsultes including your app.js file and http server creating.And now you can run your app just without "node", just write ./bin/www and click enter.

DEBUG=node:* - not sure how it works, as for me it just swicth to debug mode (I simply cut this)

To run in phpStrorm in Configuration settings, instead of .js file write ./bin/www so you will able to run your app in phpStorm debug environment.