Comments (6)
Let me take a look at the code first to check how you're using and how the require mode works then I'll get back to you.
from nodemon.
FWIW, I was able to work around this issue by exploiting utils, but surely this isn't a recommended approach:
#!/usr/bin/env node
/**
* @see https://github.com/remy/nodemon?tab=readme-ov-file#using-nodemon-as-a-module
* @see https://github.com/remy/nodemon/blob/main/doc/requireable.md
*/
const utils = require('nodemon/lib/utils/');
const nodemonLogger = require('nodemon/lib/utils/log'); // <-- import the logger so we can create a custom instance
const nodemon = require('nodemon');
utils.log = nodemonLogger(false); // <-- overwrite the logger with a custom instance, where we manually provide the value for `utils.isRequired`
// @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/nodemon/index.d.ts
const config = {
verbose: true,
watch: [ './dist' ],
delay: 2000,
exec: 'yarn run serve:dev',
// @see https://github.com/remy/nodemon?tab=readme-ov-file#application-isnt-restarting
legacyWatch: true,
}
nodemon(config);
nodemon
.on('start', function () {
console.log('test -----------------------------')
console.log(utils.log.info);
console.log(utils.log.info.toString());
utils.log.info('App has started');
})
.on('quit', function () {
utils.log.info('App has quit');
process.exit();
})
.on('restart', function (files) {
console.log('test 2 -----------------------------')
utils.log.info('App restarted due to: ', files);
});
from nodemon.
@remy I assume that there is a good reason for nodemon to be able to know whether or not it's being used as a module. Therefore, if you think it would be a reasonable approach to have a brand new configuration option for enabling built-in logging despite being required as a module, I'm happy to submit a PR for it.
from nodemon.
This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3
from nodemon.
Hey, sorry for the delay, I don't often get time to dedicate to sitting down and debugging nodemon - but I am now.
I'm not 100% sure what you need, but I'm pretty sure it's available.
The reason that nodemon wants to know if it's required or not is because when it's spawned as stand alone, it will print to stdout. When it's required, it should be quiet by default. It's also things like (quite often) if nodemon is not required, then it will exit with process.exit(n)
for help or take control of STDIN, etc.
I can see (now) that none of my examples actually show you how to get the logging (in my docs), but it is included in the message types.
You need to hook the log
event which accepts an event argument as such:
type NodemonEventLog = {
/**
detail*: what you get with nodemon --verbose.
status: subprocess starting, restarting.
fail: is the subprocess crashing.
error: is a nodemon system error.
*/
type: 'detail' | 'log' | 'status' | 'error' | 'fail';
/** the plain text message */
message: String;
/** contains the terminal escape codes to add colour, plus the "[nodemon]" prefix */
colour: String;
};
Although I've been writing JavaScript for a few decades, my TypeScript is … not the favourite thing I do, but I've started a PR that adds types to help developers, like yourself, trying to require the module: #2204
Hopefully the log
type is what you needed.
from nodemon.
Closing as per comments above.
from nodemon.
Related Issues (20)
- Restart event calls start event as well when files change HOT 3
- Passing an array into ext config HOT 5
- nodemon is not restarting server automatically HOT 1
- Ability not to signal the whole subtree of a process HOT 14
- Restart not firing beyond deletion of directory under watch, when this directory structure is recreated (on Ubuntu 22.04) HOT 12
- Nodemon ignores `--ext` argument HOT 3
- not working with Node.js version 20.12.x HOT 12
- Document differences and/or provide migration guide to Node.js native watch mode HOT 1
- Restart app on specific exit code HOT 3
- Input input cyrillic char's in python input work not well HOT 2
- Nodemon Internal watch failed HOT 5
- nodemon does not restart the server ([nodemon] restarting due to changes...) HOT 4
- Question not a bug - How to restart app on crash HOT 2
- [CVE-2024-4068] Uncontrolled resource consumption found in braces (non-issue, see comments) HOT 3
- bash node env vars for readline HOT 3
- Problem with Newley released types HOT 28
- config.env should be overridden by runtime env variables HOT 1
- [CVE-2024-4068] Uncontrolled resource consumption found in braces - Question HOT 2
- When using nodemon to upload frontend files to the backend, password encryption on the backend fails to execute correctly because nodemon reloads the index.js file. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodemon.