I'm learning Node.js + Express 4 and command that running my app looks so:
$>DEBUG=node:* ./bin/www
And what is this command do ?
How can I run my app like this:
$>node app.js
PS: I need to run under phpStrom and can't set in configuration first command.
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 node
var 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