Node.js - ejecutar un módulo si no es `required`
En Node, puede decir que su programa va a hacer dos cosas diferentes dependiendo de si se ejecuta el código require('./something.js')
o node something.js
. Esto es útil si desea interactuar con uno de sus módulos de forma independiente.
if (!module.parent) {
// ran with `node something.js`
app.listen(8088, function() {
console.log('app listening on port 8088');
})
} else {
// used with `require('/.something.js')`
module.exports = app;
}
Ver the documentation for modules para mas informacion.
![jstips book](/assets/images/book.png)
MEET THE NEW JSTIPS BOOK
You no longer need 10+ years of experience to get your dream job.
Use the 100 answers in this short book to boost your confidence and skills to ace the interviews at your favorite companies like Twitter, Google and Netflix.
GET THE BOOK NOW![jstips amazon](/book/assets/bestseller.png)
![jstips book](/assets/images/book.png)
MEET THE NEW JSTIPS BOOK
The book to ace the JavaScript Interview.
A short book with 100 answers designed to boost your knowledge and help you ace the technical interview within a few days.
GET THE BOOK NOW![jstips amazon](/book/assets/bestseller.png)