Repository: remy/nodemon Branch: main Commit: c6dd371093f4 Files: 161 Total size: 320.9 KB Directory structure: gitextract_bisxif4y/ ├── .eslintrc.json ├── .github/ │ ├── CONTRIBUTING.md │ ├── FUNDING.yml │ ├── ISSUE_TEMPLATE/ │ │ └── bug_report.md │ ├── ISSUE_TEMPLATE.md │ ├── no-response.yml │ ├── oliver.yml │ └── workflows/ │ ├── commits.yml │ ├── node.js.yml │ ├── release.yml │ ├── stale.yml │ └── website.yml ├── .gitignore ├── .jshintrc ├── .npmignore ├── .npmrc ├── .prettierrc.json ├── .releaserc ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── Dockerfile ├── LICENSE ├── README.md ├── TODO.md ├── bin/ │ └── nodemon.js ├── commitlint.config.js ├── doc/ │ ├── arch.md │ ├── cli/ │ │ ├── authors.txt │ │ ├── config.txt │ │ ├── help.txt │ │ ├── logo.txt │ │ ├── options.txt │ │ ├── topics.txt │ │ ├── usage.txt │ │ └── whoami.txt │ ├── events.md │ ├── option-parsing-logic.md │ ├── requireable.md │ ├── rules.md │ └── sample-nodemon.md ├── faq.md ├── index.d.ts ├── jsconfig.json ├── lib/ │ ├── cli/ │ │ ├── index.js │ │ └── parse.js │ ├── config/ │ │ ├── command.js │ │ ├── defaults.js │ │ ├── exec.js │ │ ├── index.js │ │ └── load.js │ ├── help/ │ │ └── index.js │ ├── index.js │ ├── monitor/ │ │ ├── index.js │ │ ├── match.js │ │ ├── run.js │ │ ├── signals.js │ │ └── watch.js │ ├── nodemon.js │ ├── rules/ │ │ ├── add.js │ │ ├── index.js │ │ └── parse.js │ ├── spawn.js │ ├── utils/ │ │ ├── bus.js │ │ ├── clone.js │ │ ├── colour.js │ │ ├── index.js │ │ ├── log.js │ │ └── merge.js │ └── version.js ├── package.json ├── test/ │ ├── cli/ │ │ ├── exec.test.js │ │ └── parse.test.js │ ├── config/ │ │ ├── env.test.js │ │ ├── load-logging.test.js │ │ └── load.test.js │ ├── docker.sh │ ├── events/ │ │ ├── complete.test.js │ │ └── scripts.test.js │ ├── fixtures/ │ │ ├── .dotfile │ │ ├── .dotfolder/ │ │ │ ├── .nested_dotfile.js │ │ │ ├── second.js │ │ │ └── some_file.js │ │ ├── 1246/ │ │ │ ├── app/ │ │ │ │ └── index.js │ │ │ └── watching/ │ │ │ └── index.js │ │ ├── app with spaces.js │ │ ├── app.coffee │ │ ├── app.js │ │ ├── comments │ │ ├── configs/ │ │ │ ├── public-star.json │ │ │ ├── top-level.json │ │ │ ├── watch-options.json │ │ │ ├── watch-relative-filter.json │ │ │ └── watch-relative.json │ │ ├── default │ │ ├── default.json │ │ ├── env.js │ │ ├── events/ │ │ │ ├── env.js │ │ │ └── nodemon.json │ │ ├── global/ │ │ │ └── nodemon.json │ │ ├── hello.ls │ │ ├── hello.py │ │ ├── help.txt │ │ ├── legacy/ │ │ │ └── .nodemonignore │ │ ├── log.coffee │ │ ├── nodemon.json │ │ ├── package.json │ │ ├── packages/ │ │ │ ├── browserify/ │ │ │ │ └── package.json │ │ │ ├── express4/ │ │ │ │ └── package.json │ │ │ ├── main-and-index/ │ │ │ │ ├── index.js │ │ │ │ ├── package.json │ │ │ │ └── server.js │ │ │ ├── main-and-start/ │ │ │ │ ├── index.js │ │ │ │ └── package.json │ │ │ ├── nodemon-settings-and-package-json-settings/ │ │ │ │ ├── nodemon.json │ │ │ │ └── package.json │ │ │ ├── package-json-settings/ │ │ │ │ └── package.json │ │ │ ├── start/ │ │ │ │ └── package.json │ │ │ ├── start-and-package-json-settings/ │ │ │ │ └── package.json │ │ │ ├── start-and-settings/ │ │ │ │ ├── nodemon.json │ │ │ │ └── package.json │ │ │ └── start-ignored/ │ │ │ └── package.json │ │ ├── regexp │ │ ├── repl.js │ │ ├── sigint.js │ │ ├── simple │ │ ├── simple.json │ │ ├── super-legacy/ │ │ │ └── nodemon-ignore │ │ └── watch-count/ │ │ ├── index.js │ │ └── lib/ │ │ ├── 1.js │ │ ├── 2.js │ │ ├── 3.js │ │ ├── 4.js │ │ └── 5.js │ ├── fork/ │ │ ├── change-detect.test.js │ │ ├── config.test.js │ │ ├── run-mac-only.test.js │ │ ├── run.test.js │ │ └── watch-restart.test.js │ ├── help/ │ │ └── help.test.js │ ├── lib/ │ │ ├── events.test.js │ │ ├── require-restartable.test.js │ │ └── require.test.js │ ├── misc/ │ │ ├── listeners.test.js │ │ └── sigint.test.js │ ├── mocha.opts │ ├── monitor/ │ │ ├── count.test.js │ │ ├── ignore.test.js │ │ ├── match.test.js │ │ ├── run.test.js │ │ ├── watch-restart.test.js │ │ └── watch.test.js │ ├── rules/ │ │ └── index.test.js │ ├── utils/ │ │ ├── colour.test.js │ │ ├── log.test.js │ │ ├── merge.test.js │ │ └── stringify.test.js │ └── utils.js └── website/ ├── index.html ├── oc.jq ├── oc.js └── style.css ================================================ FILE CONTENTS ================================================ ================================================ FILE: .eslintrc.json ================================================ { "env": { "browser": true, "commonjs": true, "es2021": true }, "parserOptions": { "ecmaVersion": 12 }, "rules": { "space-before-function-paren": [ 2, { "anonymous": "ignore", "named": "never" } ] } } ================================================ FILE: .github/CONTRIBUTING.md ================================================ # Contributing ## Commit messages Commit messages must follow the [Angular-style](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#commits) commit format (but excluding the scope). i.e: ```text fix: minified scripts being removed Also includes tests ``` This will allow for the automatic changelog to generate correctly. ## Code standards Ensure that your code adheres to the included `.jshintrc` and `.eslintrc.json` configs. ## Sending pull requests - new command line options are generally discouraged unless there's a *really* good reason - add tests for newly added code (and try to mirror directory and file structure if possible) - spell check - PRs will not be code reviewed unless all tests are passing *Important:* when fixing a bug, please commit a **failing test** first so that Travis CI (or I can) can show the code failing. Once that commit is in place, then commit the bug fix, so that we can test *before* and *after*. Remember that you're developing for multiple platforms and versions of node, so if the tests pass on your Mac or Linux or Windows machine, it *may* not pass elsewhere. I personally have Mac and Linux coverage, I need help with Windows tests. ## Issues - Please include the output from `nodemon --dump` for diagnosis - If there's a script that nodemon is having trouble with or is causing nodemon to throw exceptions, please include it in your filed issue to allow me to replicate the issue. ================================================ FILE: .github/FUNDING.yml ================================================ github: [remy] open_collective: nodemon ================================================ FILE: .github/ISSUE_TEMPLATE/bug_report.md ================================================ --- name: Bug report about: Create a report to help nodemon improve title: '' labels: '' assignees: '' --- - Versions: - `nodemon -v`: - Operating system/terminal environment (powershell, gitshell, etc): - Using Docker? What image: - Command you ran: ### Expected behaviour ### Actual behaviour ### Steps to reproduce --- If applicable, please append the `--dump` flag on your command and include the output here **ensuring to remove any sensitive/personal details or tokens**. ================================================ FILE: .github/ISSUE_TEMPLATE.md ================================================ - `nodemon -v`: - `node -v`: - Operating system/terminal environment: - Using Docker? What image: - Command you ran: ### Expected behaviour ### Actual behaviour ### Steps to reproduce --- If applicable, please append the `--dump` flag on your command and include the output here **ensuring to remove any sensitive/personal details or tokens**. ================================================ FILE: .github/no-response.yml ================================================ # Configuration for probot-no-response - https://github.com/probot/no-response # Number of days of inactivity before an Issue is closed for lack of response daysUntilClose: 7 # Label requiring a response responseRequiredLabel: "needs more info" # Comment to post when closing an Issue for lack of response. Set to `false` to disable closeComment: > This issue has been automatically closed because there hasn't been a response to my request for more information from the original author. With only the information that is currently in the issue, I don't have enough information to take action, sorry! Please comment on this issue if you have or find the answers we need so that someone can investigate further. ================================================ FILE: .github/oliver.yml ================================================ # Number of days the issue was closed in before the bot should reply. # If the issue was closed in more days than this, the bot won't reply. # Use `daysClosedIn: false` to *always* reply. daysClosedIn: 100 # Labels to look for on issues the bot can reply to labels: - bug # Comment to post when replying comment: > Thanks for raising this issue, and hopefully you're happy with @remy's fix. If you'd like to support this project, you can do just that through the open collective https://opencollective.com/nodemon/donate or at the very least, starring this project would give me @remy a little smile ❤️ ================================================ FILE: .github/workflows/commits.yml ================================================ name: Conventional Commit Checker on: pull_request: branches: [main] types: [opened, edited, synchronize] jobs: check-for-cc: runs-on: ubuntu-latest steps: - name: check-for-cc id: check-for-cc uses: agenthunt/conventional-commit-checker-action@v1.0.0 ================================================ FILE: .github/workflows/node.js.yml ================================================ # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions name: tests on: push: branches: [main] pull_request: branches: [main] jobs: build: runs-on: ubuntu-latest strategy: matrix: node-version: [18.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: cache: npm node-version: ${{ matrix.node-version }} - run: npm ci - run: npm run build --if-present - run: npm test ================================================ FILE: .github/workflows/release.yml ================================================ name: Release on: workflow_run: workflows: ["tests"] branches: [main] types: - completed jobs: release: name: Release runs-on: ubuntu-latest # This line ensures the release ONLY runs if the 'tests' workflow passed if: ${{ github.event.workflow_run.conclusion == 'success' }} permissions: contents: write id-token: write issues: write pull-requests: write steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: cache: npm node-version: 24 - name: Install dependencies run: npm ci - name: Release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # will now use the OIDC token automatically run: npx semantic-release ================================================ FILE: .github/workflows/stale.yml ================================================ name: Mark stale issues and pull requests on: schedule: - cron: "0 * * * *" jobs: stale: runs-on: ubuntu-latest permissions: issues: write pull-requests: write steps: - uses: actions/stale@v3 with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-stale: 14 days-before-close: 30 days-before-pr-close: -1 stale-issue-label: 'stale' stale-pr-label: 'stale' stale-issue-message: > 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 close-issue-message: 'Automatically closing this issue due to lack of activity' exempt-issue-labels: not-stale,security,pinned ================================================ FILE: .github/workflows/website.yml ================================================ name: website on: workflow_dispatch: jobs: deploy: runs-on: ubuntu-latest permissions: contents: write env: NETLIFY: ${{ secrets.NETLIFY }} steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: actions/setup-node@v4 with: node-version: 18 cache: npm - run: npm ci - run: node website/oc.js - name: Stage changes run: git add README.md website/index.html - name: Commit changes id: commit run: | if git diff --cached --quiet; then echo "committed=false" >> "$GITHUB_OUTPUT" exit 0 fi git config user.name "${GITHUB_ACTOR}" git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" git commit -m "chore: website" -m "[skip ci]" echo "committed=true" >> "$GITHUB_OUTPUT" - name: Push changes if: steps.commit.outputs.committed == 'true' run: git push origin HEAD - name: Trigger Netlify if: env.NETLIFY != '' run: curl -X POST "$NETLIFY" ================================================ FILE: .gitignore ================================================ lib-cov *.seed *.log *.csv *.dat *.out *.pid *.gz .env .vscode/ pids logs results npm-debug.log node_modules coverage tmp issues/ test/fixtures/test* .idea ================================================ FILE: .jshintrc ================================================ { "browser": true, "camelcase": true, "curly": true, "devel": true, "eqeqeq": true, "forin": true, "indent": 2, "noarg": true, "node": true, "quotmark": "single", "undef": true, "strict": false, "unused": true } ================================================ FILE: .npmignore ================================================ test/ tmp/ coverage/ issues/ .github/ website/ *.md Dockerfile .eslintrc.json .jshintrc .releaserc .travis.yml commitlint.config.js ================================================ FILE: .npmrc ================================================ package-lock=true ================================================ FILE: .prettierrc.json ================================================ { "singleQuote": true } ================================================ FILE: .releaserc ================================================ { "branches": ["main"] } ================================================ FILE: .travis.yml ================================================ language: node_js cache: directories: - ~/.npm notifications: email: false node_js: - '14' - '12' - '10' before_install: - if [ "$TRAVIS_PULL_REQUEST_BRANCH" == "" ]; then echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" >> .npmrc; fi after_success: - npm run semantic-release branches: except: - /^v\d+\.\d+\.\d+$/ ================================================ FILE: CODE_OF_CONDUCT.md ================================================ # Contributor Code of Conduct As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery * Personal attacks * Trolling or insulting/derogatory comments * Public or private harassment * Publishing other's private information, such as physical or electronic addresses, without explicit permission * Other unethical or unprofessional conduct. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) ================================================ FILE: Dockerfile ================================================ # # Ubuntu Node.js Dockerfile # # https://github.com/dockerfile/ubuntu/blob/master/Dockerfile # https://docs.docker.com/examples/nodejs_web_app/ # # Pull base image. FROM ubuntu:16.04 RUN apt-get update && apt-get install -y curl locales && rm -rf /var/lib/apt/lists/* \ && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 ENV LANG en_US.utf8 # Install Node.js RUN curl --silent --location https://deb.nodesource.com/setup_10.x | bash - RUN apt-get install --yes nodejs build-essential # Install app dependencies RUN npm install -g npx # Bundle app source # Trouble with COPY http://stackoverflow.com/a/30405787/2926832 # COPY . /src WORKDIR /src # Binds to port 8080 # EXPOSE 8080 # Defines your runtime(define default command) # These commands unlike RUN (they are carried out in the construction of the container) are run when the container #CMD ["node", "/src/http.js"] ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2010 - present, Remy Sharp, https://remysharp.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================

Nodemon Logo

# nodemon nodemon is a tool that helps develop Node.js based applications by automatically restarting the node application when file changes in the directory are detected. nodemon does **not** require *any* additional changes to your code or method of development. nodemon is a replacement wrapper for `node`. To use `nodemon`, replace the word `node` on the command line when executing your script. [![NPM version](https://badge.fury.io/js/nodemon.svg)](https://npmjs.org/package/nodemon) [![Backers on Open Collective](https://opencollective.com/nodemon/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/nodemon/sponsors/badge.svg)](#sponsors) # Installation Either through cloning with git or by using [npm](http://npmjs.org) (the recommended way): ```bash npm install -g nodemon # or using yarn: yarn global add nodemon ``` And nodemon will be installed globally to your system path. You can also install nodemon as a development dependency: ```bash npm install --save-dev nodemon # or using yarn: yarn add nodemon -D ``` With a local installation, nodemon will not be available in your system path or you can't use it directly from the command line. Instead, the local installation of nodemon can be run by calling it from within an npm script (such as `npm start`) or using `npx nodemon`. # Usage nodemon wraps your application, so you can pass all the arguments you would normally pass to your app: ```bash nodemon [your node app] ``` For CLI options, use the `-h` (or `--help`) argument: ```bash nodemon -h ``` Using nodemon is simple, if my application accepted a host and port as the arguments, I would start it as so: ```bash nodemon ./server.js localhost 8080 ``` Any output from this script is prefixed with `[nodemon]`, otherwise all output from your application, errors included, will be echoed out as expected. You can also pass the `inspect` flag to node through the command line as you would normally: ```bash nodemon --inspect ./server.js 80 ``` If you have a `package.json` file for your app, you can omit the main script entirely and nodemon will read the `package.json` for the `main` property and use that value as the app ([ref](https://github.com/remy/nodemon/issues/14)). nodemon will also search for the `scripts.start` property in `package.json` (as of nodemon 1.1.x). Also check out the [FAQ](https://github.com/remy/nodemon/blob/master/faq.md) or [issues](https://github.com/remy/nodemon/issues) for nodemon. ## Automatic re-running nodemon was originally written to restart hanging processes such as web servers, but now supports apps that cleanly exit. If your script exits cleanly, nodemon will continue to monitor the directory (or directories) and restart the script if there are any changes. ## Manual restarting Whilst nodemon is running, if you need to manually restart your application, instead of stopping and restart nodemon, you can type `rs` with a carriage return, and nodemon will restart your process. ## Config files nodemon supports local and global configuration files. These are usually named `nodemon.json` and can be located in the current working directory or in your home directory. An alternative local configuration file can be specified with the `--config ` option. The specificity is as follows, so that a command line argument will always override the config file settings: - command line arguments - local config - global config A config file can take any of the command line arguments as JSON key values, for example: ```json { "verbose": true, "ignore": ["*.test.js", "**/fixtures/**"], "execMap": { "rb": "ruby", "pde": "processing --sketch={{pwd}} --run" } } ``` The above `nodemon.json` file might be my global config so that I have support for ruby files and processing files, and I can run `nodemon demo.pde` and nodemon will automatically know how to run the script even though out of the box support for processing scripts. A further example of options can be seen in [sample-nodemon.md](https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md) ### package.json If you want to keep all your package configurations in one place, nodemon supports using `package.json` for configuration. Specify the config in the same format as you would for a config file but under `nodemonConfig` in the `package.json` file, for example, take the following `package.json`: ```json { "name": "nodemon", "homepage": "http://nodemon.io", "...": "... other standard package.json values", "nodemonConfig": { "ignore": ["**/test/**", "**/docs/**"], "delay": 2500 } } ``` Note that if you specify a `--config` file or provide a local `nodemon.json` any `package.json` config is ignored. *This section needs better documentation, but for now you can also see `nodemon --help config` ([also here](https://github.com/remy/nodemon/blob/master/doc/cli/config.txt))*. ## Using nodemon as a module Please see [doc/requireable.md](doc/requireable.md) ## Using nodemon as child process Please see [doc/events.md](doc/events.md#Using_nodemon_as_child_process) ## Running non-node scripts nodemon can also be used to execute and monitor other programs. nodemon will read the file extension of the script being run and monitor that extension instead of `.js` if there's no `nodemon.json`: ```bash nodemon --exec "python -v" ./app.py ``` Now nodemon will run `app.py` with python in verbose mode (note that if you're not passing args to the exec program, you don't need the quotes), and look for new or modified files with the `.py` extension. ### Default executables Using the `nodemon.json` config file, you can define your own default executables using the `execMap` property. This is particularly useful if you're working with a language that isn't supported by default by nodemon. To add support for nodemon to know about the `.pl` extension (for Perl), the `nodemon.json` file would add: ```json { "execMap": { "pl": "perl" } } ``` Now running the following, nodemon will know to use `perl` as the executable: ```bash nodemon script.pl ``` It's generally recommended to use the global `nodemon.json` to add your own `execMap` options. However, if there's a common default that's missing, this can be merged in to the project so that nodemon supports it by default, by changing [default.js](https://github.com/remy/nodemon/blob/master/lib/config/defaults.js) and sending a pull request. ## Monitoring multiple directories By default nodemon monitors the current working directory. If you want to take control of that option, use the `--watch` option to add specific paths: ```bash nodemon --watch app --watch libs app/server.js ``` Now nodemon will only restart if there are changes in the `./app` or `./libs` directory. By default nodemon will traverse sub-directories, so there's no need in explicitly including sub-directories. Nodemon also supports unix globbing, e.g `--watch './lib/*'`. The globbing pattern must be quoted. For advanced globbing, [see `picomatch` documentation](https://github.com/micromatch/picomatch#advanced-globbing), the library that nodemon uses through `chokidar` (which in turn uses it through `anymatch`). ## Specifying extension watch list By default, nodemon looks for files with the `.js`, `.mjs`, `.coffee`, `.litcoffee`, and `.json` extensions. If you use the `--exec` option and monitor `app.py` nodemon will monitor files with the extension of `.py`. However, you can specify your own list with the `-e` (or `--ext`) switch like so: ```bash nodemon -e js,pug ``` Now nodemon will restart on any changes to files in the directory (or subdirectories) with the extensions `.js`, `.pug`. ## Ignoring files By default, nodemon will only restart when a `.js` JavaScript file changes. In some cases you will want to ignore some specific files, directories or file patterns, to prevent nodemon from prematurely restarting your application. This can be done via the command line: ```bash nodemon --ignore lib/ --ignore tests/ ``` Or specific files can be ignored: ```bash nodemon --ignore lib/app.js ``` Patterns can also be ignored (but be sure to quote the arguments): ```bash nodemon --ignore 'lib/*.js' ``` **Important** the ignore rules are patterns matched to the full absolute path, and this determines how many files are monitored. If using a wild card glob pattern, it needs to be used as `**` or omitted entirely. For example, `nodemon --ignore '**/test/**'` will work, whereas `--ignore '*/test/*'` will not. Note that by default, nodemon will ignore the `.git`, `node_modules`, `bower_components`, `.nyc_output`, `coverage` and `.sass-cache` directories and *add* your ignored patterns to the list. If you want to indeed watch a directory like `node_modules`, you need to [override the underlying default ignore rules](https://github.com/remy/nodemon/blob/master/faq.md#overriding-the-underlying-default-ignore-rules). ## Application isn't restarting In some networked environments (such as a container running nodemon reading across a mounted drive), you will need to use the `legacyWatch: true` which enables Chokidar's polling. Via the CLI, use either `--legacy-watch` or `-L` for short: ```bash nodemon -L ``` Though this should be a last resort as it will poll every file it can find. ## Delaying restarting In some situations, you may want to wait until a number of files have changed. The timeout before checking for new file changes is 1 second. If you're uploading a number of files and it's taking some number of seconds, this could cause your app to restart multiple times unnecessarily. To add an extra throttle, or delay restarting, use the `--delay` command: ```bash nodemon --delay 10 server.js ``` For more precision, milliseconds can be specified. Either as a float: ```bash nodemon --delay 2.5 server.js ``` Or using the time specifier (ms): ```bash nodemon --delay 2500ms server.js ``` The delay figure is number of seconds (or milliseconds, if specified) to delay before restarting. So nodemon will only restart your app the given number of seconds after the *last* file change. If you are setting this value in `nodemon.json`, the value will always be interpreted in milliseconds. E.g., the following are equivalent: ```bash nodemon --delay 2.5 { "delay": 2500 } ``` ## Gracefully reloading down your script It is possible to have nodemon send any signal that you specify to your application. ```bash nodemon --signal SIGHUP server.js ``` Your application can handle the signal as follows. ```js process.on("SIGHUP", function () { reloadSomeConfiguration(); process.kill(process.pid, "SIGTERM"); }) ``` Please note that nodemon will send this signal to every process in the process tree. If you are using `cluster`, then each workers (as well as the master) will receive the signal. If you wish to terminate all workers on receiving a `SIGHUP`, a common pattern is to catch the `SIGHUP` in the master, and forward `SIGTERM` to all workers, while ensuring that all workers ignore `SIGHUP`. ```js if (cluster.isMaster) { process.on("SIGHUP", function () { for (const worker of Object.values(cluster.workers)) { worker.process.kill("SIGTERM"); } }); } else { process.on("SIGHUP", function() {}) } ``` ## Controlling shutdown of your script nodemon sends a kill signal to your application when it sees a file update. If you need to clean up on shutdown inside your script you can capture the kill signal and handle it yourself. The following example will listen once for the `SIGUSR2` signal (used by nodemon to restart), run the clean up process and then kill itself for nodemon to continue control: ```js // important to use `on` and not `once` as nodemon can re-send the kill signal process.on('SIGUSR2', function () { gracefulShutdown(function () { process.kill(process.pid, 'SIGTERM'); }); }); ``` Note that the `process.kill` is *only* called once your shutdown jobs are complete. Hat tip to [Benjie Gillam](http://www.benjiegillam.com/2011/08/node-js-clean-restart-and-faster-development-with-nodemon/) for writing this technique up. ## Triggering events when nodemon state changes If you want growl like notifications when nodemon restarts or to trigger an action when an event happens, then you can either `require` nodemon or add event actions to your `nodemon.json` file. For example, to trigger a notification on a Mac when nodemon restarts, `nodemon.json` looks like this: ```json { "events": { "restart": "osascript -e 'display notification \"app restarted\" with title \"nodemon\"'" } } ``` A full list of available events is listed on the [event states wiki](https://github.com/remy/nodemon/wiki/Events#states). Note that you can bind to both states and messages. ## Pipe output to somewhere else ```js nodemon({ script: ..., stdout: false // important: this tells nodemon not to output to console }).on('readable', function() { // the `readable` event indicates that data is ready to pick up this.stdout.pipe(fs.createWriteStream('output.txt')); this.stderr.pipe(fs.createWriteStream('err.txt')); }); ``` ## Using nodemon in your gulp workflow Check out the [gulp-nodemon](https://github.com/JacksonGariety/gulp-nodemon) plugin to integrate nodemon with the rest of your project's gulp workflow. ## Using nodemon in your Grunt workflow Check out the [grunt-nodemon](https://github.com/ChrisWren/grunt-nodemon) plugin to integrate nodemon with the rest of your project's grunt workflow. ## Pronunciation > nodemon, is it pronounced: node-mon, no-demon or node-e-mon (like pokémon)? Well...I've been asked this many times before. I like that I've been asked this before. There's been bets as to which one it actually is. The answer is simple, but possibly frustrating. I'm not saying (how I pronounce it). It's up to you to call it as you like. All answers are correct :) ## Design principles - Fewer flags is better - Works across all platforms - Fewer features - Let individuals build on top of nodemon - Offer all CLI functionality as an API - Contributions must have and pass tests Nodemon is not perfect, and CLI arguments has sprawled beyond where I'm completely happy, but perhaps it can be reduced a little one day. ## FAQ See the [FAQ](https://github.com/remy/nodemon/blob/master/faq.md) and please add your own questions if you think they would help others. ## Backers Thank you to all [our backers](https://opencollective.com/nodemon#backer)! 🙏 [![nodemon backers](https://opencollective.com/nodemon/backers.svg?width=890)](https://opencollective.com/nodemon#backers) ## Sponsors Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Sponsor this project today ❤️](https://opencollective.com/nodemon#sponsor)
Netpositive Best online casinos not on GamStop in the UK TheCasinoDB Goread.io Best Australian online casinos. Reviewed by Correct Casinos. nongamstopcasinos.net Buy Instagram Likes OnlineCasinosSpelen Beoordelen van nieuwe online casino's 2023 Buy real Instagram followers from Twicsy starting at only $2.97. Twicsy has been voted the best site to buy followers from the likes of US Magazine. SocialWick offers the best Instagram Followers in the market. If you are looking to boost your organic growth, buy Instagram followers from SocialWick Buy Telegram Members We review the entire iGaming industry from A to Z CryptoCasinos.online No deposit casino promo Codes 2024 - The best online Casinos websites. No deposit bonus codes, Free Spins and Promo Codes. Stake, Roobet, Jackpotcity and more. Online casino. Boost your social media presence effortlessly with top-quality Instagram and TikTok followers and likes. Social Media Management and all kinds of followers Betwinner is an online bookmaker offering sports betting, casino games, and more. At Buzzoid, you can buy Instagram followers quickly, safely, and easily with just a few clicks. Rated world's #1 IG service since 2012. Zamsino.com Reviewing and comparing online casinos available to Finnish players. In addition, we publish relevant news and blog posts about the world of iGaming. Buzzvoice is your one-stop shop for all your social media marketing needs. With Buzzvoice, you can buy followers, comments, likes, video views and more! SocialBoosting: Buy Instagram & TikTok Followers, Likes, Views Ігрові автомати онлайн Kasinohai.com Casino Online Chile casino online chile Vanguard Media évalue les casinos en ligne pour joueurs français, testant les sites en France. Nos classements stricts garantissent des casinos fiables et sûrs. Bei Releaf erhalten Sie schnell und diskret Ihr Cannabis Rezept online. Unsere Ärzte prüfen Ihre Angaben und stellen bei Eignung das Rezept aus. Anschließend können Sie legal und sicher medizinisches Cannabis über unsere Partnerapotheken kaufen. Download multithreaded HEIC to JPG converter software for Windows 10/11 We specialize in the online gambling industry, helping players access reliable and verified information about the best online casinos and pokies in Australia. Our team tests casinos and games, collects user reviews from Trustpilot, and organizes them in o Wolf Winner Casino AUCrazyVegas iDealeCasinos BetPokies.co.nz is your New Zealand guide in the world of online gambling. Our site was created by gamblers for gamblers. one x bet - Arabic betting site Online Casino Zonder Registratie We test dozens of casinos every month and select the coolest ones for Australian players. Pokies Reviews Buy TikTok Comments Mi misión es la educación y transparencia en el mundo de los casinos online Spreading knowledge about $ETH Best online sports betting and casino company. bestecasinozondercruks Best online sports betting company in Thailand. Best online sports betting company in Vietnam. We testen elke maand tientallen casino’s en kiezen de beste uit voor Nederlandse spelers. ThePokies Net Aviator Game Online Plinko Game iDEAL Casinos POLi Pay Casinos
Please note that links to the sponsors above are not direct endorsements nor affiliated with any of contributors of the nodemon project. # License MIT [http://rem.mit-license.org](http://rem.mit-license.org) ================================================ FILE: TODO.md ================================================ # TODO A rough outline of things I'd like to do with nodemon after 13 years of supporting the software: - Upgrade mocha (I tried Jest once, but it can't fork and monitor the outputs, which is how most of the tests run) - Switch to prettier from jshint (and commit formatted code) - Sweep code for unused or overly complicated code(!) ================================================ FILE: bin/nodemon.js ================================================ #!/usr/bin/env node const cli = require('../lib/cli'); const nodemon = require('../lib/'); const options = cli.parse(process.argv); nodemon(options); const fs = require('fs'); // checks for available update and returns an instance const pkg = JSON.parse(fs.readFileSync(__dirname + '/../package.json')); if (pkg.version.indexOf('0.0.0') !== 0 && options.noUpdateNotifier !== true) { require('simple-update-notifier')({ pkg }); } ================================================ FILE: commitlint.config.js ================================================ module.exports = { extends: ['@commitlint/config-conventional'], }; ================================================ FILE: doc/arch.md ================================================ # nodemon code arch ``` CLI -> parser -> nodemon options -> rules rules -> configure -> watch -> start process ``` ## CLI examples Watch src but only *.js and *.coffee nodemon --watch src/ -e js,coffee app.js Parsed to: { watch: ['src/'], ignore: [], script: 'app.js' options: { extensions: ['js', 'coffee'], exec: 'node' } } Watch with no args: nodemon Parsed to (assuming a package.json or index.js is found): { watch: [], // meaning all subdirectories ignore: [], script: 'index.js', options: { extensions: ['js'], exec: 'node' } } ================================================ FILE: doc/cli/authors.txt ================================================ Remy Sharp - author and maintainer https://github.com/remy https://twitter.com/rem Contributors: https://github.com/remy/nodemon/graphs/contributors ❤︎ Please help make nodemon better: https://github.com/remy/nodemon/ ================================================ FILE: doc/cli/config.txt ================================================ Typically the options to control nodemon are passed in via the CLI and are listed under: nodemon --help options nodemon can also be configured via a local and global config file: * $HOME/nodemon.json * $PWD/nodemon.json OR --config * nodemonConfig in package.json All config options in the .json file map 1-to-1 with the CLI options, so a config could read as: { "ext": "*.pde", "verbose": true, "exec": "processing --sketch=game --run" } There are a limited number of variables available in the config (since you could use backticks on the CLI to use a variable, backticks won't work in the .json config). * {{pwd}} - the current directory * {{filename}} - the filename you pass to nodemon For example: { "ext": "*.pde", "verbose": true, "exec": "processing --sketch={{pwd}} --run" } The global config file is useful for setting up default executables instead of repeating the same option in each of your local configs: { "verbose": true, "execMap": { "rb": "ruby", "pde": "processing --sketch={{pwd}} --run" } } ================================================ FILE: doc/cli/help.txt ================================================ Usage: nodemon [options] [script.js] [args] Options: --config file ............ alternate nodemon.json config file to use -e, --ext ................ extensions to look for, ie. js,pug,hbs. -x, --exec app ........... execute script with "app", ie. -x "python -v". -w, --watch path ......... watch directory "path" or files. use once for each directory or file to watch. -i, --ignore ............. ignore specific files or directories. -V, --verbose ............ show detail on what is causing restarts. -- ........... to tell nodemon stop slurping arguments. Note: if the script is omitted, nodemon will try to read "main" from package.json and without a nodemon.json, nodemon will monitor .js, .mjs, .coffee, .litcoffee, and .json by default. For advanced nodemon configuration use nodemon.json: nodemon --help config See also the sample: https://github.com/remy/nodemon/wiki/Sample-nodemon.json Examples: $ nodemon server.js $ nodemon -w ../foo server.js apparg1 apparg2 $ nodemon --exec python app.py $ nodemon --exec "make build" -e "styl hbs" $ nodemon app.js -- --config # pass config to app.js \x1B[1mAll options are documented under: \x1B[4mnodemon --help options\x1B[0m ================================================ FILE: doc/cli/logo.txt ================================================ ; ; kO. x0 KMX, .:x0kc. 'KMN 0MMM0: 'oKMMMMMMMXd, ;OMMMX oMMMMMWKOONMMMMMMMMMMMMMWOOKWMMMMMx OMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMK. .oWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMd. KMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMN KMMMMMMMMMMMMMMW0k0WMMMMMMMMMMMMMMW KMMMMMMMMMMMNk:. :xNMMMMMMMMMMMW KMMMMMMMMMMK OMMMMMMMMMMW KMMMMMMMMMMO xMMMMMMMMMMN KMMMMMMMMMMO xMMMMMMMMMMN KMMMMMMMMMMO xMMMMMMMMMMN KMMMMMMMMMMO xMMMMMMMMMMN KMMMMMMMMMMO xMMMMMMMMMMN KMMMMMMMMMNc ;NMMMMMMMMMN KMMMMMW0o' .lOWMMMMMN KMMKd; ,oKMMN kX: ,K0 ================================================ FILE: doc/cli/options.txt ================================================ Configuration --config .......... alternate nodemon.json config file to use --exitcrash .............. exit on crash, allows nodemon to work with other watchers -i, --ignore ............. ignore specific files or directories --no-colors .............. disable color output --signal ........ use specified kill signal instead of default (ex. SIGTERM) -w, --watch path ......... watch directory "dir" or files. use once for each directory or file to watch --no-update-notifier ..... opt-out of update version check Execution -C, --on-change-only ..... execute script on change only, not startup --cwd .............. change into before running the script -e, --ext ................ extensions to look for, ie. "js,pug,hbs" -I, --no-stdin ........... nodemon passes stdin directly to child process --spawn .................. force nodemon to use spawn (over fork) [node only] -x, --exec app ........... execute script with "app", ie. -x "python -v" -- ........... to tell nodemon stop slurping arguments Watching -d, --delay n ............ debounce restart for "n" seconds -L, --legacy-watch ....... use polling to watch for changes (typically needed when watching over a network/Docker) -P, --polling-interval ... combined with -L, milliseconds to poll for (default 100) Information --dump ................... print full debug configuration -h, --help ............... default help --help ........... help on a specific feature. Try "--help topics" -q, --quiet .............. minimise nodemon messages to start/stop only -v, --version ............ current nodemon version -V, --verbose ............ show detail on what is causing restarts > Note that any unrecognised arguments are passed to the executing command. ================================================ FILE: doc/cli/topics.txt ================================================ options .................. show all available nodemon options config ................... default config options using nodemon.json authors .................. contributors to this project logo ..................... <3 whoami ................... I, AM, NODEMON \o/ Please support https://github.com/remy/nodemon/ ================================================ FILE: doc/cli/usage.txt ================================================ Usage: nodemon [nodemon options] [script.js] [args] See "nodemon --help" for more. ================================================ FILE: doc/cli/whoami.txt ================================================ __/\\\\\_____/\\\_______/\\\\\_______/\\\\\\\\\\\\_____/\\\\\\\\\\\\\\\__/\\\\____________/\\\\_______/\\\\\_______/\\\\\_____/\\\_ _\/\\\\\\___\/\\\_____/\\\///\\\____\/\\\////////\\\__\/\\\///////////__\/\\\\\\________/\\\\\\_____/\\\///\\\____\/\\\\\\___\/\\\_ _\/\\\/\\\__\/\\\___/\\\/__\///\\\__\/\\\______\//\\\_\/\\\_____________\/\\\//\\\____/\\\//\\\___/\\\/__\///\\\__\/\\\/\\\__\/\\\_ _\/\\\//\\\_\/\\\__/\\\______\//\\\_\/\\\_______\/\\\_\/\\\\\\\\\\\_____\/\\\\///\\\/\\\/_\/\\\__/\\\______\//\\\_\/\\\//\\\_\/\\\_ _\/\\\\//\\\\/\\\_\/\\\_______\/\\\_\/\\\_______\/\\\_\/\\\///////______\/\\\__\///\\\/___\/\\\_\/\\\_______\/\\\_\/\\\\//\\\\/\\\_ _\/\\\_\//\\\/\\\_\//\\\______/\\\__\/\\\_______\/\\\_\/\\\_____________\/\\\____\///_____\/\\\_\//\\\______/\\\__\/\\\_\//\\\/\\\_ _\/\\\__\//\\\\\\__\///\\\__/\\\____\/\\\_______/\\\__\/\\\_____________\/\\\_____________\/\\\__\///\\\__/\\\____\/\\\__\//\\\\\\_ _\/\\\___\//\\\\\____\///\\\\\/_____\/\\\\\\\\\\\\/___\/\\\\\\\\\\\\\\\_\/\\\_____________\/\\\____\///\\\\\/_____\/\\\___\//\\\\\_ _\///_____\/////_______\/////_______\////////////_____\///////////////__\///______________\///_______\/////_______\///_____\/////__ ================================================ FILE: doc/events.md ================================================ # Events nodemon will emit events based on the child process. ## Commands - restart - config:update - quit ## States - start - child process has started - crash - child process has crashed (nodemon will not emit exit) - exit - child process has cleanly exited (ie. no crash) - restart([ array of files triggering the restart ]) - child process has restarted - config:update - nodemon's config has changed ## Messages - log({ type, message (plain text log), colour (colour coded log) }) - logging from nodemon (not the child process) - stdout - the stdout stream from the child process - stderr - the stderr stream from the child process - readable - stdout and stderr streams are ready ([example](https://github.com/remy/nodemon#pipe-output-to-somewhere-else)) Note that if you want to supress the normal stdout & stderr of the child, in favour of processing the stream manually using the stdout/stderr nodemon events, pass nodemon the option of `stdout: false`. ## Using nodemon events If nodemon is required, events can be bound and emitted on the nodemon object: ```js var nodemon = require('nodemon'); nodemon({ script: 'app.js' }).on('start', function () { console.log('nodemon started'); }).on('crash', function () { console.log('script crashed for some reason'); }); // force a restart nodemon.emit('restart'); // force a quit nodemon.emit('quit'); ``` ## Using nodemon as child process If nodemon is a spawned process, then the child (nodemon) will emit message events whereby the event argument contains the event type, and instead of emitting events, you `send` the command: ```js // using `spawn` as example, can use other functions like `fork`, etc // https://nodejs.org/api/child_process.html const { spawn } = require('child_process'); function spawnNodemon() { const cp = spawn('nodemon', ['path/to/file.js', '--watch', 'path/to/watch'], { // the important part is the 4th option 'ipc' // this way `process.send` will be available in the child process (nodemon) // so it can communicate back with parent process (through `.on()`, `.send()`) // https://nodejs.org/api/child_process.html#child_process_options_stdio stdio: ['pipe', 'pipe', 'pipe', 'ipc'], }); return cp; } var app = spawnNodemon(); app.on('message', function (event) { if (event.type === 'start') { console.log('nodemon started'); } else if (event.type === 'crash') { console.log('script crashed for some reason'); } }); // force a restart app.send('restart'); // force a quit app.send('quit'); ``` Note that even though the child will still emit a `message` event whose type is `exit`, it makes more sense to listen to the actual `exit` event on the child: ```js app.on('exit', function () { console.log('nodemon quit'); }); ``` ================================================ FILE: doc/option-parsing-logic.md ================================================ # Option parsing logic 1. Read all CLI arguments 2. Load local config 3. Load global config 4. Try backup: package.main 5. Try backup: package.start 6. Try index.js ================================================ FILE: doc/requireable.md ================================================ # Nodemon as a required module Nodemon (as of 1.0.0) also works as a required module. At present, you can only require nodemon in to your project once (as there are static config variables), but you can re-run with new settings for a different application to monitor. By requiring nodemon, you can extend it's functionality. Below is a simple example of using nodemon in your project: ```js var nodemon = require('nodemon'); nodemon({ script: 'app.js', ext: 'js json' }); nodemon.on('start', function () { console.log('App has started'); }).on('quit', function () { console.log('App has quit'); process.exit(); }).on('restart', function (files) { console.log('App restarted due to: ', files); }); ``` Nodemon will emit a number of [events](https://github.com/remy/nodemon/blob/master/doc/events.md) by default, and when in verbose mode will also emit a `log` event (which matches what the nodemon cli tool echos). ## Arguments The `nodemon` function takes either an object (that matches the [nodemon config](https://github.com/remy/nodemon#config-files)) or can take a string that matches the arguments that would be used on the command line: ```js var nodemon = require('nodemon'); nodemon('-e "js json" app.js'); ``` ## Methods & Properties The `nodemon` object also has a few methods and properties. Some are exposed to help with tests, but have been listed here for completeness: ### Event handling This is the event emitter bus that exists inside nodemon exposed at the top level module (ie. it's the `events` api): - `nodemon.on(event, fn)` - `nodemon.addListener(event, fn)` - `nodemon.once(event, fn)` - `nodemon.emit(event)` - `nodemon.removeAllListeners([event])` Note: there's no `removeListener` (happy to take a pull request if it's needed). ### Test utilities - `nodemon.reset()` - reverts nodemon's internal state to a clean slate - `nodemon.config` - a reference to the internal config nodemon uses ================================================ FILE: doc/rules.md ================================================ # Rules Given a nodemon.json file that contains: ```json { "ignore": ["*.coffee"], "watch": ["server/*.coffee", "test/"] } ``` Then nodemon detects changes, but what causes nodemon to restart? The ignored files or the watched files? Which wins? ```js const files = ['server/foo.coffee', 'server/app.js']; // afterIgnore = ['server/app.js'] now since foo.coffee matches *.coffee const afterIgnore = files.filter(applyIgnore); // watch = ['server/foo.coffee'] as it's under the watch const watched = files.filter(applyWatch); ``` What about: ```js const files = ['test/app.js', 'test/app.coffee']; // afterIgnore = ['test/app.js'] now since test/app.coffee matches *.coffee const afterIgnore = files.filter(applyIgnore); // watch.length = 2 as watch implies test/*.* const watched = files.filter(applyWatch); ``` ================================================ FILE: doc/sample-nodemon.md ================================================ # Sample nodemon.json Here is an example (of a contrived) `nodemon.json` file: ```json { "restartable": "rs", "ignore": [ ".git", "node_modules/**/node_modules" ], "verbose": true, "execMap": { "js": "node --harmony" }, "events": { "restart": "osascript -e 'display notification \"App restarted due to:\n'$FILENAME'\" with title \"nodemon\"'" }, "watch": [ "test/fixtures/", "test/samples/" ], "env": { "NODE_ENV": "development" }, "ext": "js,json" } ``` Note that the `ignore` used is nodemon's default ignore rule. The complete defaults can be seen here: [defaults.js](https://github.com/remy/nodemon/blob/master/lib/config/defaults.js). ================================================ FILE: faq.md ================================================ # FAQ This is being added to as common issues occur on the [issues](http://github.com/remy/nodemon/issues), and where appropriate the answers will be added here. This is a working document, and if it makes sense, I'll take pull requests to help make it better. # How to clear the console on restart Rather than being a(nother) feature in nodemon, and as per the [design principles](https://github.com/remy/nodemon#design-principles) you can clear the console using nodemon's existing architecture. In your `nodemon.json` (or in your `package.json`) you can include the follow event handler to always clear the console when nodemon starts: ```json { "events": { "start": "cls || clear" } } ``` Note that on Windows, this will clear the scroll buffer too. If you try to use node to clear the screen, you may have a race condition between the boot time of your process and the start event. This method should be the fastest. # nodemon doesn't restart on .env change This is an edge case with how nodemon watches files. This is because nodemon doesn't know if `.env` is a hidden file with no extension or a `*.env` without a filename. Nonetheless, to trigger a change on `.env` (or similar files like `.bash_profile`), you need to explicitly tell nodemon to watch the file. However, now nodemon will *only* watch the `.env` file, so you need to add to what nodemon is watching, i.e. tell nodemon to _also_ watch the current working directory: ```bash $ nodemon --watch .env --watch app app/index.js ``` # nodemon doesn't work with my REPL Create an nodemon.json file with the setting: ```js { "restartable": false } ``` This will leave the STDIN to your application rather than listening for the `rs` command to restart. # Strange/failing behaviour starting the (node-based) executable By default, nodemon will try to fork your node scripts ([background reading](https://github.com/remy/nodemon/issues/1025)), however, there are some edge cases where that won't suit your needs. Most of the time the default configuration should be fine, but if you want to force nodemon to spawn your node process, use the `--spawn` option. # My script arguments are being taken by nodemon Use the `--` switch to tell nodemon to ignore all arguments after this point. So to pass `-L` to your script instead of nodemon, use: ``` $ nodemon app.js -- -L -opt2 -opt3 ``` nodemon will ignore all script arguments after `--` and pass them to your script. # Error: "process failed, unhandled exit code (2)" Nodemon will look for exit signals from the child process it runs. When the exit code is `2`, nodemon throws an error. Typically this is because the arguments are bad for the executing program, but it can also be due other reasons. For example, mocha@3.x will exit with `2` on failing tests. To handle the exit code in a way that nodemon can consume, manually exit the process, i.e.: ```bash nodemon -x 'mocha test/bad.test.js || exit 1' ``` # You want to suppress the request for support message Perhaps you're [already supporting nodemon](https://opencollective.com/nodemon) or you're using it in CI and it needs to be quietened. Include the environment value of `SUPPRESS_SUPPORT=1`. # Can't install nodemon: permission issue You may need to install nodemon using `sudo` (which isn't recommended, but I understand it's unavoidable in some environments). If the install fails with this appearing in the npm error log, then you need the following workaround. ``` gyp WARN EACCES user "root" does not have permission to access the dev dir "" ``` Try to re-install adding `--unsafe-perm` to the arguments: ``` sudo npm install -g nodemon --unsafe-perm ``` Ref [#713](https://github.com/remy/nodemon/issues/713) # Help! My changes aren't being detected! nodemon (from 1.4.2 onwards) uses [Chokidar](https://www.npmjs.com/package/chokidar) as its underlying watch system. If you find your files aren't being monitored, either nodemon isn't restarting, or it reports that zero files are being watched, then you may need the polling mode. To enable polling use the legacy flag either via the terminal: ```shell $ nodemon --legacy-watch $ nodemon -L # short alias ``` Or via the `nodemon.json`: ```json { "legacyWatch": true } ``` ## nodemon tries to run two scripts If you see nodemon trying to run two scripts, like: ``` 9 Dec 23:52:58 - [nodemon] starting `node ./app.js fixtures/sigint.js` ``` This is because the main script argument (`fixtures/sigint.js` in this case) wasn't found, and a `package.json`'s main file _was_ found. ie. to solve, double check the path to your script is correct. ## What has precedence, ignore or watch? Everything under the ignore rule has the final word. So if you ignore the `node_modules` directory, but watch `node_modules/*.js`, then all changed files will be ignored, because any changed .js file in the `node_modules` are ignored. However, there are defaults in the ignore rules that your rules will be merged with, and not override. To override the ignore rules see [overriding the underlying default ignore rules](#overriding-the-underlying-default-ignore-rules). ## Overriding the underlying default ignore rules The way the ignore rules work is that your rules are merged with the `ignoreRoot` rules, which contain `['.git', 'node_modules', ...]`. So if you ignore `public`, the ignore rule results in `['.git', 'node_modules', ..., 'public']`. Say you did want to watch the `node_modules` directory. You have to override the `ignoreRoot`. If you wanted this on a per project basis, add the config to you local `nodemon.json`. If you want it for all projects, add it to `$HOME/nodemon.json`: ```json { "ignoreRoot": [".git"] } ``` Now when ignoring `public`, the ignore rule results in `['.git', 'public']`, and nodemon will restart on `node_modules` changes. ## nodemon doesn't work with fedora Fedora is looking for `nodejs` rather than `node` which is the binary that nodemon kicks off. A workaround is to make sure that `node` binary exists in the `PATH`: ```bash sudo ln -s /usr/bin/nodejs /usr/local/bin/node ``` Alternatively the `--exec nodejs` option can be used. Fedora and Ubuntu package node as nodejs, because node.dpkg is > Description-en: Amateur Packet Radio Node program > The node program accepts TCP/IP and packet radio network connections and > presents users with an interface that allows them to make gateway connections > to remote hosts using a variety of amateur radio protocols. > They make the binary is nodejs, rather than node. So long as you're not using that Packet Radio Node Program mentioned above the workaround will work. Thank you [@EvanCarroll](https://github.com/remy/nodemon/issues/68#issuecomment-13672509) ## Using nodemon with forever If you're using nodemon with [forever](https://github.com/foreverjs/forever) (perhaps in a production environment), you can combine the two together. This way if the script crashes, forever restarts the script, and if there are file changes, nodemon restarts your script. For more detail, see [issue 30](https://github.com/remy/nodemon/issues/30). To achieve this you need to add the following on the call to `forever`: * Use forever's `-c nodemon` option to tell forever to run `nodemon` instead of `node`. * Include the nodemon `--exitcrash` flag to ensure nodemon exits if the script crashes (or exits unexpectedly). * Tell forever to use `SIGTERM` instead of `SIGKILL` when requesting nodemon to stop. This ensures that nodemon can stop the watched node process cleanly. * Optionally add the `--uid` parameter, adding a unique name for your process. In the example, the uid is set to `foo`. ```bash forever start --uid foo --killSignal=SIGTERM -c 'nodemon --exitcrash' server.js ``` To test this, you can kill the server.js process and forever will restart it. If you `touch server.js` nodemon will restart it. To stop the process monitored by forever and nodemon, call the following, using the `uid` we assigned above (`foo`): ```bash forever stop foo ``` This will stop both nodemon and the node process it was monitoring. Note that I _would not_ recommend using nodemon in a production environment - but that's because I wouldn't want it restart without my explicit instruction. ## What does "verbose" give me? The `--verbose` (or `-V`) puts nodemon in verbose mode which adds some detail to starting and restarting. Additional restart information: * Which nodemon configs are loaded (local and global if found) * Which ignore rules are being applied * Which file extensions are being watch * The process ID of your application (the `child pid`) * The process ID of nodemon to manually trigger restarts via kill signals For example: ```text 14 Apr 15:24:58 - [nodemon] v1.0.17 14 Apr 15:24:58 - [nodemon] reading config /Users/remy/Sites/jsbin-private/nodemon.json 14 Apr 15:24:58 - [nodemon] to restart at any time, enter `rs` 14 Apr 15:24:58 - [nodemon] or send SIGHUP to 58118 to restart 14 Apr 15:24:58 - [nodemon] ignoring: /Users/remy/Sites/jsbin-private/.git/**/* node_modules/**/node_modules 14 Apr 15:24:58 - [nodemon] watching: /Users/remy/Sites/jsbin/views/**/* /Users/remy/Sites/jsbin/lib/**/* ../json/*.json config.dev.json 14 Apr 15:24:58 - [nodemon] watching extensions: json,js,html 14 Apr 15:24:58 - [nodemon] starting `node run.js` 14 Apr 15:24:58 - [nodemon] child pid: 9292 ``` When nodemon detects a change, the following addition information is shown: * Which file(s) triggered the check * Which (if any) rules the file matched to cause a subsequent restart * How many rules were matched and out of those rules, how many cause a restart * A list of all the files that _successfully_ caused a restart For example, on `lib/app.js` being changed: ```text 14 Apr 15:25:56 - [nodemon] files triggering change check: ../jsbin/lib/app.js 14 Apr 15:25:56 - [nodemon] matched rule: **/Users/remy/Sites/jsbin/lib/**/* 14 Apr 15:25:56 - [nodemon] changes after filters (before/after): 1/1 14 Apr 15:25:56 - [nodemon] restarting due to changes... 14 Apr 15:25:56 - [nodemon] ../jsbin/lib/app.js 14 Apr 15:25:56 - [nodemon] starting `node run.js` 14 Apr 15:25:56 - [nodemon] child pid: 9556 ``` ## My .nodemonignore is being ignored _The legacy `.nodemonignore` was dropped in nodemon@3_ The new `nodemon.json` supersedes the `.nodemonignore` file, so if you have both, the `.nodemonignore` is not used at all. Note that if you have a `nodemon.json` in your `$HOME` path, then this will also supersede the old ignore file (and the _legacy_ format config is ignored). ## nodemon does nothing On Ubuntu globally installed node applications have been found to have no output when they're run. This _seems_ to be an issue with node not being correctly installed (possibly linked to the binary having to be called `nodejs`). The solution (that's worked in the past) is to install [nvm](https://github.com/creationix/nvm) first and using it to install node, _rather_ than using `apt-get` (or similar tools) to install node directly. ## If nodemon is facing the watch errors (Mac & Linux) Try the following command on terminal: ```bash echo fs.inotify.max_user_watches=582222 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p ``` ## "Port in use" with --inspect flag and docker The workaround is to use [kill-port](https://github.com/tiaanduplessis/kill-port) to close off the debugger port, used similarly to: ```bash nodemon --delay 80ms --exec 'kill-port -k 9228/tcp; node --inspect=0.0.0.0:9228 ./app/http.js' ``` [Original suggestion here](https://github.com/remy/nodemon/issues/1050#issuecomment-323680697) and [addition information here](https://github.com/remy/nodemon/issues/1346#issuecomment-401218386). ## Windows: nodemon keeps restarting without changes This _might_ be related to a Microsoft Windows release pertaining to the OS and breaking `fsevents` module (which is used by [chokidar](https://github.com/paulmillr/chokidar) - the underlying watch package). The workaround is to run the following command: ```bash fsutil behavior set disablelastaccess 1 ``` [Futher reading thread](https://github.com/remy/nodemon/issues/1354) ## Error: Cannot find module 'internal/util/types' If you see the error `Cannot find module 'internal/util/types'`, the error is solved with a clean npm cache and trying to reinstall the dependency you're working with. A start is to use the following commands: ``` sudo npm cache clean --force sudo npm i -g npm ``` Otherwise see [issue #1124](https://github.com/remy/nodemon/issues/1124) for further suggestions. ## No automatic restart when using Docker volumes [issue #419](https://github.com/remy/nodemon/issues/419#issuecomment-391244911) Some Node.js Docker images do not seem to have the full suite of filesystem process utilities that allow `nodemon` to restart automatically when the code in a mounted volume changes. To handle this, and enable automatic restarts without using legacy mode, you can install the [procps](http://procps.sourceforge.net) package. Here's an example snippet of a Dockerfile: ``` FROM node:8.9.4-wheezy RUN apt-get update && apt-get install -y procps ``` ## "scripts is disabled on this system" on Windows Based on [this issue](https://github.com/remy/nodemon/issues/1619), if you see the following on Windows: ``` PS> nodemon app.js nodemon : File C:\…\nodemon.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:1 CategoryInfo : SecurityError: (:) [], PSSecurityException FullyQualifiedErrorId : UnauthorizedAccess ``` The solution is as follows by [Felipe Jacob](https://github.com/adelbs): It's a security restriction of the Windows PowerShell. 1. Open up a powershell command window (open it as administrator) 2. To check out current restrictions type "Get-ExecutionPolicy" 3. Enable powershell by typing "Set-ExecutionPolicy remotesigned" ## How can I watch all file types in a folder? To watch all file types, use `'*'`: ```bash nodemon --ext '*' --watch public --exec 'python -m SimpleHTTPServer' ``` ## Workaround for when --inspect flag is passed and the old process doesn't finish before starting a new process Based on [this issue](https://github.com/remy/nodemon/issues/2056). Sometimes when using the `--inspect` flag, nodemon will try to start the a process before the old process is finished. This will cause an error trying to up the new process because of the debugger service: ``` [0] [nodemon] restarting due to changes... [0] [nodemon] starting `node --inspect ./main/index.js` [0] Starting inspector on 127.0.0.1:9229 failed: address already in use ``` Your application will likely be running the old version code if you see that message, and you will need to stop the app and manually start it again to run the app with the newer code version. A common cause for this is when graceful shutdowns are doing async tasks, i.e: ``` // ensure this is `on` and not `once` process.on('SIGUSR2', async () => { await db.disconnect() process.kill(process.pid, 'SIGTERM'); }) ``` Simply removing the `await` keyword would likely fix the issue. If even after that you still running into that problem, there's a workaround to force kill the debugger whenever nodemon triggers a restart. You can create a `nodemon.json` file at the project root and add the following config: ``` { "events": { "restart": "sh -c 'lsof -i :${PORT:-9229} -t | xargs kill'" } } ``` This will run a shell command to kill the process running on the PORT 9229 (default node debug port) whenever nodemon triggers a restart. It may fail sometimes, but it makes the hot reload works partially. ================================================ FILE: index.d.ts ================================================ import type { WatchOptions } from 'chokidar'; export type NodemonEventHandler = | 'start' | 'crash' | 'exit' | 'quit' | 'restart' | 'config:update' | 'log' | 'readable' | 'stdout' | 'stderr'; export type NodemonEventListener = { on(event: 'start' | 'crash' | 'readable', listener: () => void): Nodemon; on(event: 'log', listener: (e: NodemonEventLog) => void): Nodemon; on(event: 'stdout' | 'stderr', listener: (e: string) => void): Nodemon; on(event: 'restart', listener: (files?: string[]) => void): Nodemon; on(event: 'quit', listener: (e?: NodemonEventQuit) => void): Nodemon; on(event: 'exit', listener: (e?: number) => void): Nodemon; on( event: 'config:update', listener: (e?: NodemonEventConfig) => void, ): Nodemon; }; export 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; }; export type NodemonEventQuit = 143 | 130; export type NodemonEventConfig = { run: boolean; system: { cwd: string; }; required: boolean; dirs: string[]; timeout: number; options: NodemonConfig; lastStarted: number; loaded: string[]; load: ( settings: NodemonSettings, ready: (config: NodemonEventConfig) => void, ) => void; reset: () => void; }; export interface NodemonExecOptions { script: string; scriptPosition?: number; args?: string[]; ext?: string; // "js,mjs" etc (should really support an array of strings, but I don't think it does right now) exec?: string; // node, python, etc execArgs?: string[]; // args passed to node, etc, nodeArgs?: string[]; // args passed to node, etc, } export interface NodemonConfig { /** restartable defaults to "rs" as a string the user enters */ restartable?: false | string; colours?: boolean; execMap?: { [key: string]: string }; ignoreRoot?: string[]; watch?: string[]; ignore?: string[]; stdin?: boolean; runOnChangeOnly?: boolean; verbose?: boolean; signal?: string; stdout?: boolean; watchOptions?: WatchOptions; help?: string; version?: boolean; cwd?: string; dump?: boolean; delay?: number; monitor?: string[]; spawn?: boolean; noUpdateNotifier?: boolean; legacyWatch?: boolean; pollingInterval?: number; /** @deprecated as this is "on" by default */ js?: boolean; quiet?: boolean; configFile?: string; exitCrash?: boolean; execOptions?: NodemonExecOptions; } export interface NodemonSettings extends NodemonConfig, NodemonExecOptions { events?: Record; env?: Record; } export type Nodemon = { (settings: NodemonSettings): Nodemon; removeAllListeners(event: NodemonEventHandler): Nodemon; emit(type: NodemonEventHandler, event?: any): Nodemon; reset(callback: Function): Nodemon; restart(): Nodemon; config: NodemonSettings; } & NodemonEventListener & { [K in keyof NodemonEventListener as 'addListener']: NodemonEventListener[K]; } & { [K in keyof NodemonEventListener as 'once']: NodemonEventListener[K]; }; declare const nodemon: Nodemon; export = nodemon; ================================================ FILE: jsconfig.json ================================================ { "compilerOptions": { "typeRoots": ["./index.d.ts", "./node_modules/@types"], "checkJs": true }, "exclude": ["node_modules"] } ================================================ FILE: lib/cli/index.js ================================================ var parse = require('./parse'); /** * Converts a string to command line args, in particular * groups together quoted values. * This is a utility function to allow calling nodemon as a required * library, but with the CLI args passed in (instead of an object). * * @param {String} string * @return {Array} */ function stringToArgs(string) { var args = []; var parts = string.split(' '); var length = parts.length; var i = 0; var open = false; var grouped = ''; var lead = ''; for (; i < length; i++) { lead = parts[i].substring(0, 1); if (lead === '"' || lead === '\'') { open = lead; grouped = parts[i].substring(1); } else if (open && parts[i].slice(-1) === open) { open = false; grouped += ' ' + parts[i].slice(0, -1); args.push(grouped); } else if (open) { grouped += ' ' + parts[i]; } else { args.push(parts[i]); } } return args; } module.exports = { parse: function (argv) { if (typeof argv === 'string') { argv = stringToArgs(argv); } return parse(argv); }, }; ================================================ FILE: lib/cli/parse.js ================================================ /* nodemon is a utility for node, and replaces the use of the executable node. So the user calls `nodemon foo.js` instead. nodemon can be run in a number of ways: `nodemon` - tries to use package.json#main property to run `nodemon` - if no package, looks for index.js `nodemon app.js` - runs app.js `nodemon --arg app.js --apparg` - eats arg1, and runs app.js with apparg `nodemon --apparg` - as above, but passes apparg to package.json#main (or index.js) `nodemon --debug app.js */ var fs = require('fs'); var path = require('path'); var existsSync = fs.existsSync || path.existsSync; module.exports = parse; /** * Parses the command line arguments `process.argv` and returns the * nodemon options, the user script and the executable script. * * @param {Array | string} argv full process arguments, including `node` leading arg * @return {Object} { options, script, args } */ function parse(argv) { if (typeof argv === 'string') { argv = argv.split(' '); } var eat = function (i, args) { if (i <= args.length) { return args.splice(i + 1, 1).pop(); } }; var args = argv.slice(2); var script = null; var nodemonOptions = { scriptPosition: null }; var nodemonOpt = nodemonOption.bind(null, nodemonOptions); var lookForArgs = true; // move forward through the arguments for (var i = 0; i < args.length; i++) { // if the argument looks like a file, then stop eating if (!script) { if (args[i] === '.' || existsSync(args[i])) { script = args.splice(i, 1).pop(); // we capture the position of the script because we'll reinsert it in // the right place in run.js:command (though I'm not sure we should even // take it out of the array in the first place, but this solves passing // arguments to the exec process for now). nodemonOptions.scriptPosition = i; i--; continue; } } if (lookForArgs) { // respect the standard way of saying: hereafter belongs to my script if (args[i] === '--') { args.splice(i, 1); nodemonOptions.scriptPosition = i; // cycle back one argument, as we just ate this one up i--; // ignore all further nodemon arguments lookForArgs = false; // move to the next iteration continue; } if (nodemonOpt(args[i], eat.bind(null, i, args)) !== false) { args.splice(i, 1); // cycle back one argument, as we just ate this one up i--; } } } nodemonOptions.script = script; nodemonOptions.args = args; return nodemonOptions; } /** * Given an argument (ie. from process.argv), sets nodemon * options and can eat up the argument value * * @param {import('../..').NodemonSettings} options object that will be updated * @param {String} arg current argument from argv * @param {Function} eatNext the callback to eat up the next argument in argv * @return {Boolean} false if argument was not a nodemon arg */ function nodemonOption(options, arg, eatNext) { // line separation on purpose to help legibility if (arg === '--help' || arg === '-h' || arg === '-?') { var help = eatNext(); options.help = help ? help : true; } else if (arg === '--version' || arg === '-v') { options.version = true; } else if (arg === '--no-update-notifier') { options.noUpdateNotifier = true; } else if (arg === '--spawn') { options.spawn = true; } else if (arg === '--dump') { options.dump = true; } else if (arg === '--verbose' || arg === '-V') { options.verbose = true; } else if (arg === '--legacy-watch' || arg === '-L') { options.legacyWatch = true; } else if (arg === '--polling-interval' || arg === '-P') { options.pollingInterval = parseInt(eatNext(), 10); } else // Depricated as this is "on" by default if (arg === '--js') { options.js = true; } else if (arg === '--quiet' || arg === '-q') { options.quiet = true; } else if (arg === '--config') { options.configFile = eatNext(); } else if (arg === '--watch' || arg === '-w') { if (!options.watch) { options.watch = []; } options.watch.push(eatNext()); } else if (arg === '--ignore' || arg === '-i') { if (!options.ignore) { options.ignore = []; } options.ignore.push(eatNext()); } else if (arg === '--exitcrash') { options.exitCrash = true; } else if (arg === '--delay' || arg === '-d') { options.delay = parseDelay(eatNext()); } else if (arg === '--exec' || arg === '-x') { options.exec = eatNext(); } else if (arg === '--no-stdin' || arg === '-I') { options.stdin = false; } else if (arg === '--on-change-only' || arg === '-C') { options.runOnChangeOnly = true; } else if (arg === '--ext' || arg === '-e') { options.ext = eatNext(); } else if (arg === '--no-colours' || arg === '--no-colors') { options.colours = false; } else if (arg === '--signal' || arg === '-s') { options.signal = eatNext(); } else if (arg === '--cwd') { options.cwd = eatNext(); // go ahead and change directory. This is primarily for nodemon tools like // grunt-nodemon - we're doing this early because it will affect where the // user script is searched for. process.chdir(path.resolve(options.cwd)); } else { // this means we didn't match return false; } } /** * Given an argument (ie. from nodemonOption()), will parse and return the * equivalent millisecond value or 0 if the argument cannot be parsed * * @param {String} value argument value given to the --delay option * @return {Number} millisecond equivalent of the argument */ function parseDelay(value) { var millisPerSecond = 1000; var millis = 0; if (value.match(/^\d*ms$/)) { // Explicitly parse for milliseconds when using ms time specifier millis = parseInt(value, 10); } else { // Otherwise, parse for seconds, with or without time specifier then convert millis = parseFloat(value) * millisPerSecond; } return isNaN(millis) ? 0 : millis; } ================================================ FILE: lib/config/command.js ================================================ module.exports = command; /** * command constructs the executable command to run in a shell including the * user script, the command arguments. * * @param {Object} settings Object as: * { execOptions: { * exec: String, * [script: String], * [scriptPosition: Number], * [execArgs: Array] * } * } * @return {Object} an object with the node executable and the * arguments to the command */ function command(settings) { var options = settings.execOptions; var executable = options.exec; var args = []; // after "executable" go the exec args (like --debug, etc) if (options.execArgs) { [].push.apply(args, options.execArgs); } // then goes the user's script arguments if (options.args) { [].push.apply(args, options.args); } // after the "executable" goes the user's script if (options.script) { args.splice((options.scriptPosition || 0) + options.execArgs.length, 0, options.script); } return { executable: executable, args: args, }; } ================================================ FILE: lib/config/defaults.js ================================================ var ignoreRoot = require('ignore-by-default').directories(); // default options for config.options const defaults = { restartable: 'rs', colours: true, execMap: { py: 'python', rb: 'ruby', ts: 'ts-node', // more can be added here such as ls: lsc - but please ensure it's cross // compatible with linux, mac and windows, or make the default.js // dynamically append the `.cmd` for node based utilities }, ignoreRoot: ignoreRoot.map((_) => `**/${_}/**`), watch: ['*.*'], stdin: true, runOnChangeOnly: false, verbose: false, signal: 'SIGUSR2', // 'stdout' refers to the default behaviour of a required nodemon's child, // but also includes stderr. If this is false, data is still dispatched via // nodemon.on('stdout/stderr') stdout: true, watchOptions: {}, }; const nodeOptions = process.env.NODE_OPTIONS || ''; // ? if (/--(loader|import)\b/.test(nodeOptions)) { delete defaults.execMap.ts; } module.exports = defaults; ================================================ FILE: lib/config/exec.js ================================================ const path = require('path'); const fs = require('fs'); const existsSync = fs.existsSync; const utils = require('../utils'); module.exports = exec; module.exports.expandScript = expandScript; /** * Reads the cwd/package.json file and looks to see if it can load a script * and possibly an exec first from package.main, then package.start. * * @return {Object} exec & script if found */ function execFromPackage() { // doing a try/catch because we can't use the path.exist callback pattern // or we could, but the code would get messy, so this will do exactly // what we're after - if the file doesn't exist, it'll throw. try { // note: this isn't nodemon's package, it's the user's cwd package var pkg = require(path.join(process.cwd(), 'package.json')); if (pkg.main !== undefined) { // no app found to run - so give them a tip and get the feck out return { exec: null, script: pkg.main }; } if (pkg.scripts && pkg.scripts.start) { const parts = pkg.scripts.start.split(' '); // fixes a loop issue where the script repeats over and over #2258 if (parts.includes('nodemon')) { return null; } return { exec: pkg.scripts.start }; } } catch (e) {} return null; } function replace(map, str) { var re = new RegExp('{{(' + Object.keys(map).join('|') + ')}}', 'g'); return str.replace(re, function (all, m) { return map[m] || all || ''; }); } function expandScript(script, ext) { if (!ext) { ext = '.js'; } if (script.indexOf(ext) !== -1) { return script; } if (existsSync(path.resolve(script))) { return script; } if (existsSync(path.resolve(script + ext))) { return script + ext; } return script; } /** * Discovers all the options required to run the script * and if a custom exec has been passed in, then it will * also try to work out what extensions to monitor and * whether there's a special way of running that script. * * @param {Object} nodemonOptions * @param {Object} execMap * @return {Object} new and updated version of nodemonOptions */ function exec(nodemonOptions, execMap) { if (!execMap) { execMap = {}; } var options = utils.clone(nodemonOptions || {}); var script; // if there's no script passed, try to get it from the first argument if (!options.script && (options.args || []).length) { script = expandScript( options.args[0], options.ext && '.' + (options.ext || 'js').split(',')[0] ); // if the script was found, shift it off our args if (script !== options.args[0]) { options.script = script; options.args.shift(); } } // if there's no exec found yet, then try to read it from the local // package.json this logic used to sit in the cli/parse, but actually the cli // should be parsed first, then the user options (via nodemon.json) then // finally default down to pot shots at the directory via package.json if (!options.exec && !options.script) { var found = execFromPackage(); if (found !== null) { if (found.exec) { options.exec = found.exec; } if (!options.script) { options.script = found.script; } if (Array.isArray(options.args) && options.scriptPosition === null) { options.scriptPosition = options.args.length; } } } // var options = utils.clone(nodemonOptions || {}); script = path.basename(options.script || ''); var scriptExt = path.extname(script).slice(1); var extension = options.ext; if (extension === undefined) { var isJS = scriptExt === 'js' || scriptExt === 'mjs' || scriptExt === 'cjs'; extension = isJS || !scriptExt ? 'js,mjs,cjs' : scriptExt; extension += ',json'; // Always watch JSON files } var execDefined = !!options.exec; // allows the user to simplify cli usage: // https://github.com/remy/nodemon/issues/195 // but always give preference to the user defined argument if (!options.exec && execMap[scriptExt] !== undefined) { options.exec = execMap[scriptExt]; execDefined = true; } options.execArgs = nodemonOptions.execArgs || []; if (Array.isArray(options.exec)) { options.execArgs = options.exec; options.exec = options.execArgs.shift(); } if (options.exec === undefined) { options.exec = 'node'; } else { // allow variable substitution for {{filename}} and {{pwd}} var substitution = replace.bind(null, { filename: options.script, pwd: process.cwd(), }); var newExec = substitution(options.exec); if ( newExec !== options.exec && options.exec.indexOf('{{filename}}') !== -1 ) { options.script = null; } options.exec = newExec; var newExecArgs = options.execArgs.map(substitution); if (newExecArgs.join('') !== options.execArgs.join('')) { options.execArgs = newExecArgs; delete options.script; } } if (options.exec === 'node' && options.nodeArgs && options.nodeArgs.length) { options.execArgs = options.execArgs.concat(options.nodeArgs); } // note: indexOf('coffee') handles both .coffee and .litcoffee if ( !execDefined && options.exec === 'node' && scriptExt.indexOf('coffee') !== -1 ) { options.exec = 'coffee'; // we need to get execArgs set before the script // for example, in `nodemon --debug my-script.coffee --my-flag`, debug is an // execArg, while my-flag is a script arg var leadingArgs = (options.args || []).splice(0, options.scriptPosition); options.execArgs = options.execArgs.concat(leadingArgs); options.scriptPosition = 0; if (options.execArgs.length > 0) { // because this is the coffee executable, we need to combine the exec args // into a single argument after the nodejs flag options.execArgs = ['--nodejs', options.execArgs.join(' ')]; } } if (options.exec === 'coffee') { // don't override user specified extension tracking if (options.ext === undefined) { if (extension) { extension += ','; } extension += 'coffee,litcoffee'; } // because windows can't find 'coffee', it needs the real file 'coffee.cmd' if (utils.isWindows) { options.exec += '.cmd'; } } // allow users to make a mistake on the extension to monitor // converts .js, pug => js,pug // BIG NOTE: user can't do this: nodemon -e *.js // because the terminal will automatically expand the glob against // the file system :( extension = (extension.match(/[^,*\s]+/g) || []) .map((ext) => ext.replace(/^\./, '')) .join(','); options.ext = extension; if (options.script) { options.script = expandScript( options.script, extension && '.' + extension.split(',')[0] ); } options.env = {}; // make sure it's an object (and since we don't have ) if ({}.toString.apply(nodemonOptions.env) === '[object Object]') { options.env = utils.clone(nodemonOptions.env); } else if (nodemonOptions.env !== undefined) { throw new Error('nodemon env values must be an object: { PORT: 8000 }'); } return options; } ================================================ FILE: lib/config/index.js ================================================ /** * Manages the internal config of nodemon, checking for the state of support * with fs.watch, how nodemon can watch files (using find or fs methods). * * This is *not* the user's config. */ var debug = require('debug')('nodemon'); var load = require('./load'); var rules = require('../rules'); var utils = require('../utils'); var pinVersion = require('../version').pin; var command = require('./command'); var rulesToMonitor = require('../monitor/match').rulesToMonitor; var bus = utils.bus; function reset() { rules.reset(); config.dirs = []; config.options = { ignore: [], watch: [], monitor: [] }; config.lastStarted = 0; config.loaded = []; } var config = { run: false, system: { cwd: process.cwd(), }, required: false, dirs: [], timeout: 1000, options: {}, }; /** * Take user defined settings, then detect the local machine capability, then * look for local and global nodemon.json files and merge together the final * settings with the config for nodemon. * * @param {Object} settings user defined settings for nodemon (typically on * the cli) * @param {Function} ready callback fired once the config is loaded */ config.load = function (settings, ready) { reset(); var config = this; load(settings, config.options, config, function (options) { config.options = options; if (options.watch.length === 0) { // this is to catch when the watch is left blank options.watch.push('*.*'); } if (options['watch_interval']) { // jshint ignore:line options.watchInterval = options['watch_interval']; // jshint ignore:line } config.watchInterval = options.watchInterval || null; if (options.signal) { config.signal = options.signal; } var cmd = command(config.options); config.command = { raw: cmd, string: utils.stringify(cmd.executable, cmd.args), }; // now run automatic checks on system adding to the config object options.monitor = rulesToMonitor(options.watch, options.ignore, config); var cwd = process.cwd(); debug('config: dirs', config.dirs); if (config.dirs.length === 0) { config.dirs.unshift(cwd); } bus.emit('config:update', config); pinVersion().then(function () { ready(config); }).catch(e => { // this doesn't help testing, but does give exposure on syntax errors console.error(e.stack); setTimeout(() => { throw e; }, 0); }); }); }; config.reset = reset; module.exports = config; ================================================ FILE: lib/config/load.js ================================================ var debug = require('debug')('nodemon'); var fs = require('fs'); var path = require('path'); var exists = fs.exists || path.exists; var utils = require('../utils'); var rules = require('../rules'); var parse = require('../rules/parse'); var exec = require('./exec'); var defaults = require('./defaults'); module.exports = load; module.exports.mutateExecOptions = mutateExecOptions; var existsSync = fs.existsSync || path.existsSync; function findAppScript() { // nodemon has been run alone, so try to read the package file // or try to read the index.js file var pkg = existsSync(path.join(process.cwd(), 'package.json')) && require(path.join(process.cwd(), 'package.json')); if ((!pkg || pkg.main == undefined) && existsSync('./index.js')) { return 'index.js'; } } /** * Load the nodemon config, first reading the global root/nodemon.json, then * the local nodemon.json to the exec and then overwriting using any user * specified settings (i.e. from the cli) * * @param {Object} settings user defined settings * @param {Object} options global options * @param {Object} config the config object to be updated * @param {Function} callback that receives complete config */ function load(settings, options, config, callback) { config.loaded = []; // first load the root nodemon.json loadFile(options, config, utils.home, function (options) { // then load the user's local configuration file if (settings.configFile) { options.configFile = path.resolve(settings.configFile); } loadFile(options, config, process.cwd(), function (options) { // Then merge over with the user settings (parsed from the cli). // Note that merge protects and favours existing values over new values, // and thus command line arguments get priority options = utils.merge(settings, options); // legacy support if (!Array.isArray(options.ignore)) { options.ignore = [options.ignore]; } if (!options.ignoreRoot) { options.ignoreRoot = defaults.ignoreRoot; } // blend the user ignore and the default ignore together if (options.ignoreRoot && options.ignore) { if (!Array.isArray(options.ignoreRoot)) { options.ignoreRoot = [options.ignoreRoot]; } options.ignore = options.ignoreRoot.concat(options.ignore); } else { options.ignore = defaults.ignore.concat(options.ignore); } // add in any missing defaults options = utils.merge(options, defaults); if (!options.script && !options.exec) { var found = findAppScript(); if (found) { if (!options.args) { options.args = []; } // if the script is found as a result of not being on the command // line, then we move any of the pre double-dash args in execArgs const n = options.scriptPosition === null ? options.args.length : options.scriptPosition; options.execArgs = (options.execArgs || []).concat( options.args.splice(0, n) ); options.scriptPosition = null; options.script = found; } } mutateExecOptions(options); if (options.quiet) { utils.quiet(); } if (options.verbose) { utils.debug = true; } // simplify the ready callback to be called after the rules are normalised // from strings to regexp through the rules lib. Note that this gets // created *after* options is overwritten twice in the lines above. var ready = function (options) { normaliseRules(options, callback); }; ready(options); }); }); } function normaliseRules(options, ready) { // convert ignore and watch options to rules/regexp rules.watch.add(options.watch); rules.ignore.add(options.ignore); // normalise the watch and ignore arrays options.watch = options.watch === false ? false : rules.rules.watch; options.ignore = rules.rules.ignore; ready(options); } /** * Looks for a config in the current working directory, and a config in the * user's home directory, merging the two together, giving priority to local * config. This can then be overwritten later by command line arguments * * @param {Function} ready callback to pass loaded settings to */ function loadFile(options, config, dir, ready) { if (!ready) { ready = function () {}; } var callback = function (settings) { // prefer the local nodemon.json and fill in missing items using // the global options ready(utils.merge(settings, options)); }; if (!dir) { return callback({}); } var filename = options.configFile || path.join(dir, 'nodemon.json'); if (config.loaded.indexOf(filename) !== -1) { // don't bother re-parsing the same config file return callback({}); } fs.readFile(filename, 'utf8', function (err, data) { if (err) { if (err.code === 'ENOENT') { if (!options.configFile && dir !== utils.home) { // if no specified local config file and local nodemon.json // doesn't exist, try the package.json return loadPackageJSON(config, callback); } } return callback({}); } var settings = {}; try { settings = JSON.parse(data.toString('utf8').replace(/^\uFEFF/, '')); if (!filename.endsWith('package.json') || settings.nodemonConfig) { config.loaded.push(filename); } } catch (e) { utils.log.fail('Failed to parse config ' + filename); console.error(e); process.exit(1); } // options values will overwrite settings callback(settings); }); } function loadPackageJSON(config, ready) { if (!ready) { ready = () => {}; } const dir = process.cwd(); const filename = path.join(dir, 'package.json'); const packageLoadOptions = { configFile: filename }; return loadFile(packageLoadOptions, config, dir, (settings) => { ready(settings.nodemonConfig || {}); }); } function mutateExecOptions(options) { // work out the execOptions based on the final config we have options.execOptions = exec( { script: options.script, exec: options.exec, args: options.args, scriptPosition: options.scriptPosition, nodeArgs: options.nodeArgs, execArgs: options.execArgs, ext: options.ext, env: options.env, }, options.execMap ); // clean up values that we don't need at the top level delete options.scriptPosition; delete options.script; delete options.args; delete options.ext; return options; } ================================================ FILE: lib/help/index.js ================================================ var fs = require('fs'); var path = require('path'); const supportsColor = require('supports-color'); module.exports = help; const highlight = supportsColor.stdout ? '\x1B\[$1m' : ''; function help(item) { if (!item) { item = 'help'; } else if (item === true) { // if used with -h or --help and no args item = 'help'; } // cleanse the filename to only contain letters // aka: /\W/g but figured this was eaiser to read item = item.replace(/[^a-z]/gi, ''); try { var dir = path.join(__dirname, '..', '..', 'doc', 'cli', item + '.txt'); var body = fs.readFileSync(dir, 'utf8'); return body.replace(/\\x1B\[(.)m/g, highlight); } catch (e) { return '"' + item + '" help can\'t be found'; } } ================================================ FILE: lib/index.js ================================================ module.exports = require('./nodemon'); ================================================ FILE: lib/monitor/index.js ================================================ module.exports = { run: require('./run'), watch: require('./watch').watch, }; ================================================ FILE: lib/monitor/match.js ================================================ const { minimatch } = require('minimatch'); const path = require('path'); const fs = require('fs'); const debug = require('debug')('nodemon:match'); const utils = require('../utils'); module.exports = match; module.exports.rulesToMonitor = rulesToMonitor; function rulesToMonitor(watch, ignore, config) { var monitor = []; if (!Array.isArray(ignore)) { if (ignore) { ignore = [ignore]; } else { ignore = []; } } if (!Array.isArray(watch)) { if (watch) { watch = [watch]; } else { watch = []; } } if (watch && watch.length) { monitor = utils.clone(watch); } if (ignore) { [].push.apply( monitor, (ignore || []).map(function (rule) { return '!' + rule; }) ); } var cwd = process.cwd(); // next check if the monitored paths are actual directories // or just patterns - and expand the rule to include *.* monitor = monitor.map(function (rule) { var not = rule.slice(0, 1) === '!'; if (not) { rule = rule.slice(1); } if (rule === '.' || rule === '.*') { rule = '*.*'; } var dir = path.resolve(cwd, rule); try { var stat = fs.statSync(dir); if (stat.isDirectory()) { rule = dir; if (rule.slice(-1) !== '/') { rule += '/'; } rule += '**/*'; // `!not` ... sorry. if (!not) { config.dirs.push(dir); } } else { // ensures we end up in the check that tries to get a base directory // and then adds it to the watch list throw new Error(); } } catch (e) { var base = tryBaseDir(dir); if (!not && base) { if (config.dirs.indexOf(base) === -1) { config.dirs.push(base); } } } if (rule.slice(-1) === '/') { // just slap on a * anyway rule += '*'; } // if the url ends with * but not **/* and not *.* // then convert to **/* - somehow it was missed :-\ if ( rule.slice(-4) !== '**/*' && rule.slice(-1) === '*' && rule.indexOf('*.') === -1 ) { if (rule.slice(-2) !== '**') { rule += '*/*'; } } return (not ? '!' : '') + rule; }); return monitor; } function tryBaseDir(dir) { var stat; if (/[?*\{\[]+/.test(dir)) { // if this is pattern, then try to find the base try { var base = path.dirname(dir.replace(/([?*\{\[]+.*$)/, 'foo')); stat = fs.statSync(base); if (stat.isDirectory()) { return base; } } catch (error) { // console.log(error); } } else { try { stat = fs.statSync(dir); // if this path is actually a single file that exists, then just monitor // that, *specifically*. if (stat.isFile() || stat.isDirectory()) { return dir; } } catch (e) { } } return false; } function match(files, monitor, ext) { // sort the rules by highest specificity (based on number of slashes) // ignore rules (!) get sorted highest as they take precedent const cwd = process.cwd(); var rules = monitor .sort(function (a, b) { var r = b.split(path.sep).length - a.split(path.sep).length; var aIsIgnore = a.slice(0, 1) === '!'; var bIsIgnore = b.slice(0, 1) === '!'; if (aIsIgnore || bIsIgnore) { if (aIsIgnore) { return -1; } return 1; } if (r === 0) { return b.length - a.length; } return r; }) .map(function (s) { var prefix = s.slice(0, 1); if (prefix === '!') { if (s.indexOf('!' + cwd) === 0) { return s; } // if it starts with a period, then let's get the relative path if (s.indexOf('!.') === 0) { return '!' + path.resolve(cwd, s.substring(1)); } return '!**' + (prefix !== path.sep ? path.sep : '') + s.slice(1); } // if it starts with a period, then let's get the relative path if (s.indexOf('.') === 0) { return path.resolve(cwd, s); } if (s.indexOf(cwd) === 0) { return s; } return '**' + (prefix !== path.sep ? path.sep : '') + s; }); debug('rules', rules); var good = []; var whitelist = []; // files that we won't check against the extension var ignored = 0; var watched = 0; var usedRules = []; var minimatchOpts = { dot: true, }; // enable case-insensitivity on Windows if (utils.isWindows) { minimatchOpts.nocase = true; minimatchOpts.windowsPathsNoEscape = true; } files.forEach(function (file) { file = path.resolve(cwd, file); var matched = false; for (var i = 0; i < rules.length; i++) { if (rules[i].slice(0, 1) === '!') { if (!minimatch(file, rules[i], minimatchOpts)) { debug('ignored', file, 'rule:', rules[i]); ignored++; matched = true; break; } } else { debug('matched', file, 'rule:', rules[i]); if (minimatch(file, rules[i], minimatchOpts)) { watched++; // don't repeat the output if a rule is matched if (usedRules.indexOf(rules[i]) === -1) { usedRules.push(rules[i]); utils.log.detail('matched rule: ' + rules[i]); } // if the rule doesn't match the WATCH EVERYTHING // but *does* match a rule that ends with *.*, then // white list it - in that we don't run it through // the extension check too. if ( rules[i] !== '**' + path.sep + '*.*' && rules[i].slice(-3) === '*.*' ) { whitelist.push(file); } else if (path.basename(file) === path.basename(rules[i])) { // if the file matches the actual rule, then it's put on whitelist whitelist.push(file); } else { good.push(file); } matched = true; } else { // utils.log.detail('no match: ' + rules[i], file); } } } if (!matched) { ignored++; } }); // finally check the good files against the extensions that we're monitoring if (ext) { if (ext.indexOf(',') === -1) { ext = '**/*.' + ext; } else { ext = '**/*.{' + ext + '}'; } good = good.filter(function (file) { // only compare the filename to the extension test return minimatch(path.basename(file), ext, minimatchOpts); }); debug('good (filtered by ext)', good); } else { // else assume *.* debug('good', good); } if (whitelist.length) debug('whitelist', whitelist); var result = good.concat(whitelist); if (utils.isWindows) { // fix for windows testing - I *think* this is okay to do result = result.map(function (file) { return file.slice(0, 1).toLowerCase() + file.slice(1); }); } return { result: result, ignored: ignored, watched: watched, total: files.length, }; } ================================================ FILE: lib/monitor/run.js ================================================ var debug = require('debug')('nodemon:run'); const statSync = require('fs').statSync; var utils = require('../utils'); var bus = utils.bus; var childProcess = require('child_process'); var spawn = childProcess.spawn; var exec = childProcess.exec; var execSync = childProcess.execSync; var fork = childProcess.fork; var watch = require('./watch').watch; var config = require('../config'); var child = null; // the actual child process we spawn var killedAfterChange = false; var noop = () => {}; var restart = null; var psTree = require('pstree.remy'); var path = require('path'); var signals = require('./signals'); const undefsafe = require('undefsafe'); const osRelease = parseInt(require('os').release().split('.')[0], 10); function run(options) { var cmd = config.command.raw; // moved up // we need restart function below in the global scope for run.kill /*jshint validthis:true*/ restart = run.bind(this, options); run.restart = restart; // binding options with instance of run // so that we can use it in run.kill run.options = options; var runCmd = !options.runOnChangeOnly || config.lastStarted !== 0; if (runCmd) { utils.log.status('starting `' + config.command.string + '`'); } else { // should just watch file if command is not to be run // had another alternate approach // to stop process being forked/spawned in the below code // but this approach does early exit and makes code cleaner debug('start watch on: %s', config.options.watch); if (config.options.watch !== false) { watch(); return; } } config.lastStarted = Date.now(); var stdio = ['pipe', 'pipe', 'pipe']; if (config.options.stdout) { stdio = ['pipe', process.stdout, process.stderr]; } if (config.options.stdin === false) { stdio = [process.stdin, process.stdout, process.stderr]; } var sh = 'sh'; var shFlag = '-c'; const binPath = process.cwd() + '/node_modules/.bin'; const spawnOptions = { env: Object.assign({}, options.execOptions.env, process.env, { PATH: binPath + path.delimiter + (undefsafe(options, '.execOptions.env.PATH') || process.env.PATH), }), stdio: stdio, }; var executable = cmd.executable; if (utils.isWindows) { // if the exec includes a forward slash, reverse it for windows compat // but *only* apply to the first command, and none of the arguments. // ref #1251 and #1236 if (executable.indexOf('/') !== -1) { executable = executable .split(' ') .map((e, i) => { if (i === 0) { return path.normalize(e); } return e; }) .join(' '); } // taken from npm's cli: https://git.io/vNFD4 sh = process.env.comspec || 'cmd'; shFlag = '/d /s /c'; spawnOptions.windowsVerbatimArguments = true; spawnOptions.windowsHide = true; } var args = runCmd ? utils.stringify(executable, cmd.args) : ':'; var spawnArgs = [sh, [shFlag, args], spawnOptions]; const firstArg = cmd.args[0] || ''; var inBinPath = false; try { inBinPath = statSync(`${binPath}/${executable}`).isFile(); } catch (e) {} // hasStdio allows us to correctly handle stdin piping // see: https://git.io/vNtX3 const hasStdio = utils.satisfies('>= 6.4.0 || < 5'); // forking helps with sub-process handling and tends to clean up better // than spawning, but it should only be used under specific conditions const shouldFork = !config.options.spawn && !inBinPath && !(firstArg.indexOf('-') === 0) && // don't fork if there's a node exec arg firstArg !== 'inspect' && // don't fork it's `inspect` debugger executable === 'node' && // only fork if node utils.version.major > 4; // only fork if node version > 4 if (shouldFork) { // this assumes the first argument is the script and slices it out, since // we're forking var forkArgs = cmd.args.slice(1); var env = utils.merge(options.execOptions.env, process.env); stdio.push('ipc'); const forkOptions = { env: env, stdio: stdio, silent: !hasStdio, }; if (utils.isWindows) { forkOptions.windowsHide = true; } child = fork(options.execOptions.script, forkArgs, forkOptions); utils.log.detail('forking'); debug('fork', sh, shFlag, args); } else { utils.log.detail('spawning'); child = spawn.apply(null, spawnArgs); debug('spawn', sh, shFlag, args); } if (config.required) { var emit = { stdout: function (data) { bus.emit('stdout', data); }, stderr: function (data) { bus.emit('stderr', data); }, }; // now work out what to bind to... if (config.options.stdout) { child.on('stdout', emit.stdout).on('stderr', emit.stderr); } else { child.stdout.on('data', emit.stdout); child.stderr.on('data', emit.stderr); bus.stdout = child.stdout; bus.stderr = child.stderr; } if (shouldFork) { child.on('message', function (message, sendHandle) { bus.emit('message', message, sendHandle); }); } } bus.emit('start'); utils.log.detail('child pid: ' + child.pid); child.on('error', function (error) { bus.emit('error', error); if (error.code === 'ENOENT') { utils.log.error('unable to run executable: "' + cmd.executable + '"'); process.exit(1); } else { utils.log.error('failed to start child process: ' + error.code); throw error; } }); child.on('exit', function (code, signal) { if (child && child.stdin) { process.stdin.unpipe(child.stdin); } if (code === 127) { utils.log.error( 'failed to start process, "' + cmd.executable + '" exec not found' ); bus.emit('error', code); process.exit(); } // If the command failed with code 2, it may or may not be a syntax error // See: http://git.io/fNOAR // We will only assume a parse error, if the child failed quickly if (code === 2 && Date.now() < config.lastStarted + 500) { utils.log.error('process failed, unhandled exit code (2)'); utils.log.error(''); utils.log.error('Either the command has a syntax error,'); utils.log.error('or it is exiting with reserved code 2.'); utils.log.error(''); utils.log.error('To keep nodemon running even after a code 2,'); utils.log.error('add this to the end of your command: || exit 1'); utils.log.error(''); utils.log.error('Read more here: https://git.io/fNOAG'); utils.log.error(''); utils.log.error('nodemon will stop now so that you can fix the command.'); utils.log.error(''); bus.emit('error', code); process.exit(); } // In case we killed the app ourselves, set the signal thusly if (killedAfterChange) { killedAfterChange = false; signal = config.signal; } // this is nasty, but it gives it windows support if (utils.isWindows && signal === 'SIGTERM') { signal = config.signal; } if (signal === config.signal || code === 0) { // this was a clean exit, so emit exit, rather than crash debug('bus.emit(exit) via ' + config.signal); bus.emit('exit', signal); // exit the monitor, but do it gracefully if (signal === config.signal) { return restart(); } if (code === 0) { // clean exit - wait until file change to restart if (runCmd) { utils.log.status('clean exit - waiting for changes before restart'); } child = null; } } else { bus.emit('crash'); // support the old syntax of `exitcrash` - 2024-12-13 if (options.exitcrash) { options.exitCrash = true; delete options.exitcrash; } if (options.exitCrash) { utils.log.fail('app crashed'); if (!config.required) { process.exit(1); } } else { utils.log.fail( 'app crashed - waiting for file changes before' + ' starting...' ); child = null; } } if (config.options.restartable) { // stdin needs to kick in again to be able to listen to the // restart command process.stdin.resume(); } }); // moved the run.kill outside to handle both the cases // intial start // no start // connect stdin to the child process (options.stdin is on by default) if (options.stdin) { process.stdin.resume(); // FIXME decide whether or not we need to decide the encoding // process.stdin.setEncoding('utf8'); // swallow the stdin error if it happens // ref: https://github.com/remy/nodemon/issues/1195 if (hasStdio) { child.stdin.on('error', () => {}); process.stdin.pipe(child.stdin); } else { if (child.stdout) { child.stdout.pipe(process.stdout); } else { utils.log.error( 'running an unsupported version of node ' + process.version ); utils.log.error( 'nodemon may not work as expected - ' + 'please consider upgrading to LTS' ); } } bus.once('exit', function () { if (child && process.stdin.unpipe) { // node > 0.8 process.stdin.unpipe(child.stdin); } }); } debug('start watch on: %s', config.options.watch); if (config.options.watch !== false) { watch(); } } function waitForSubProcesses(pid, callback) { debug('checking ps tree for pids of ' + pid); psTree(pid, (err, pids) => { if (!pids.length) { return callback(); } utils.log.status( `still waiting for ${pids.length} sub-process${ pids.length > 2 ? 'es' : '' } to finish...` ); setTimeout(() => waitForSubProcesses(pid, callback), 1000); }); } function kill(child, signal, callback) { if (!callback) { callback = noop; } if (utils.isWindows) { const taskKill = () => { try { exec('taskkill /pid ' + child.pid + ' /T /F'); } catch (e) { utils.log.error('Could not shutdown sub process cleanly'); } }; // We are handling a 'SIGKILL' , 'SIGUSR2' and 'SIGUSR1' POSIX signal under Windows the // same way it is handled on a UNIX system: We are performing // a hard shutdown without waiting for the process to clean-up. if ( signal === 'SIGKILL' || osRelease < 10 || signal === 'SIGUSR2' || signal === 'SIGUSR1' ) { debug('terminating process group by force: %s', child.pid); // We are using the taskkill utility to terminate the whole // process group ('/t') of the child ('/pid') by force ('/f'). // We need to end all sub processes, because the 'child' // process in this context is actually a cmd.exe wrapper. taskKill(); callback(); return; } try { // We are using the Windows Management Instrumentation Command-line // (wmic.exe) to resolve the sub-child process identifier, because the // 'child' process in this context is actually a cmd.exe wrapper. // We want to send the termination signal directly to the node process. // The '2> nul' silences the no process found error message. const resultBuffer = execSync( `wmic process where (ParentProcessId=${child.pid}) get ProcessId 2> nul` ); const result = resultBuffer.toString().match(/^[0-9]+/m); // If there is no sub-child process we fall back to the child process. const processId = Array.isArray(result) ? result[0] : child.pid; debug('sending kill signal SIGINT to process: %s', processId); // We are using the standalone 'windows-kill' executable to send the // standard POSIX signal 'SIGINT' to the node process. This fixes #1720. const windowsKill = path.normalize( `${__dirname}/../../bin/windows-kill.exe` ); // We have to detach the 'windows-kill' execution completely from this // process group to avoid terminating the nodemon process itself. // See: https://github.com/alirdn/windows-kill#how-it-works--limitations // // Therefore we are using 'start' to create a new cmd.exe context. // The '/min' option hides the new terminal window and the '/wait' // option lets the process wait for the command to finish. execSync( `start "windows-kill" /min /wait "${windowsKill}" -SIGINT ${processId}` ); } catch (e) { taskKill(); } callback(); } else { // we use psTree to kill the full subtree of nodemon, because when // spawning processes like `coffee` under the `--debug` flag, it'll spawn // it's own child, and that can't be killed by nodemon, so psTree gives us // an array of PIDs that have spawned under nodemon, and we send each the // configured signal (default: SIGUSR2) signal, which fixes #335 // note that psTree also works if `ps` is missing by looking in /proc let sig = signal.replace('SIG', ''); psTree(child.pid, function (err, pids) { // if ps isn't native to the OS, then we need to send the numeric value // for the signal during the kill, `signals` is a lookup table for that. if (!psTree.hasPS) { sig = signals[signal]; } // the sub processes need to be killed from smallest to largest debug('sending kill signal to ' + pids.join(', ')); child.kill(signal); pids.sort().forEach((pid) => exec(`kill -${sig} ${pid}`, noop)); waitForSubProcesses(child.pid, () => { // finally kill the main user process exec(`kill -${sig} ${child.pid}`, callback); }); }); } } run.kill = function (noRestart, callback) { // I hate code like this :( - Remy (author of said code) if (typeof noRestart === 'function') { callback = noRestart; noRestart = false; } if (!callback) { callback = noop; } if (child !== null) { // if the stdin piping is on, we need to unpipe, but also close stdin on // the child, otherwise linux can throw EPIPE or ECONNRESET errors. if (run.options.stdin) { process.stdin.unpipe(child.stdin); } // For the on('exit', ...) handler above the following looks like a // crash, so we set the killedAfterChange flag if a restart is planned if (!noRestart) { killedAfterChange = true; } /* Now kill the entire subtree of processes belonging to nodemon */ var oldPid = child.pid; if (child) { kill(child, config.signal, function () { // this seems to fix the 0.11.x issue with the "rs" restart command, // though I'm unsure why. it seems like more data is streamed in to // stdin after we close. if (child && run.options.stdin && child.stdin && oldPid === child.pid) { child.stdin.end(); } callback(); }); } } else if (!noRestart) { // if there's no child, then we need to manually start the process // this is because as there was no child, the child.on('exit') event // handler doesn't exist which would normally trigger the restart. bus.once('start', callback); run.restart(); } else { callback(); } }; run.restart = noop; bus.on('quit', function onQuit(code) { if (code === undefined) { code = 0; } // remove event listener var exitTimer = null; var exit = function () { clearTimeout(exitTimer); exit = noop; // null out in case of race condition child = null; if (!config.required) { // Execute all other quit listeners. bus.listeners('quit').forEach(function (listener) { if (listener !== onQuit) { listener(); } }); process.exit(code); } else { bus.emit('exit'); } }; // if we're not running already, don't bother with trying to kill if (config.run === false) { return exit(); } // immediately try to stop any polling config.run = false; if (child) { // give up waiting for the kids after 10 seconds exitTimer = setTimeout(exit, 10 * 1000); child.removeAllListeners('exit'); child.once('exit', exit); kill(child, 'SIGINT'); } else { exit(); } }); bus.on('restart', function () { // run.kill will send a SIGINT to the child process, which will cause it // to terminate, which in turn uses the 'exit' event handler to restart run.kill(); }); // remove the child file on exit process.on('exit', function () { utils.log.detail('exiting'); if (child) { child.kill(); } }); // because windows borks when listening for the SIG* events if (!utils.isWindows) { bus.once('boot', () => { // usual suspect: ctrl+c exit process.once('SIGINT', () => bus.emit('quit', 130)); process.once('SIGTERM', () => { bus.emit('quit', 143); if (child) { child.kill('SIGTERM'); } }); }); } module.exports = run; ================================================ FILE: lib/monitor/signals.js ================================================ module.exports = { SIGHUP: 1, SIGINT: 2, SIGQUIT: 3, SIGILL: 4, SIGTRAP: 5, SIGABRT: 6, SIGBUS: 7, SIGFPE: 8, SIGKILL: 9, SIGUSR1: 10, SIGSEGV: 11, SIGUSR2: 12, SIGPIPE: 13, SIGALRM: 14, SIGTERM: 15, SIGSTKFLT: 16, SIGCHLD: 17, SIGCONT: 18, SIGSTOP: 19, SIGTSTP: 20, SIGTTIN: 21, SIGTTOU: 22, SIGURG: 23, SIGXCPU: 24, SIGXFSZ: 25, SIGVTALRM: 26, SIGPROF: 27, SIGWINCH: 28, SIGIO: 29, SIGPWR: 30, SIGSYS: 31, SIGRTMIN: 35, } ================================================ FILE: lib/monitor/watch.js ================================================ module.exports.watch = watch; module.exports.resetWatchers = resetWatchers; var debug = require('debug')('nodemon:watch'); var debugRoot = require('debug')('nodemon'); var chokidar = require('chokidar'); var undefsafe = require('undefsafe'); var config = require('../config'); var path = require('path'); var utils = require('../utils'); var bus = utils.bus; var match = require('./match'); var watchers = []; var debouncedBus; bus.on('reset', resetWatchers); function resetWatchers() { debugRoot('resetting watchers'); watchers.forEach(function (watcher) { watcher.close(); }); watchers = []; } function watch() { if (watchers.length) { debug('early exit on watch, still watching (%s)', watchers.length); return; } var dirs = [].slice.call(config.dirs); debugRoot('start watch on: %s', dirs.join(', ')); const rootIgnored = config.options.ignore; debugRoot('ignored', rootIgnored); var watchedFiles = []; const promise = new Promise(function (resolve) { const dotFilePattern = /[/\\]\./; var ignored = match.rulesToMonitor( [], // not needed Array.from(rootIgnored), config ).map(pattern => pattern.slice(1)); const addDotFile = dirs.filter(dir => dir.match(dotFilePattern)); // don't ignore dotfiles if explicitly watched. if (addDotFile.length === 0) { ignored.push(dotFilePattern); } var watchOptions = { ignorePermissionErrors: true, ignored: ignored, persistent: true, usePolling: config.options.legacyWatch || false, interval: config.options.pollingInterval, // note to future developer: I've gone back and forth on adding `cwd` // to the props and in some cases it fixes bugs but typically it causes // bugs elsewhere (since nodemon is used is so many ways). the final // decision is to *not* use it at all and work around it // cwd: ... }; if (utils.isWindows) { watchOptions.disableGlobbing = true; } if (utils.isIBMi) { watchOptions.usePolling = true; } if (process.env.TEST) { watchOptions.useFsEvents = false; } var watcher = chokidar.watch( dirs, Object.assign({}, watchOptions, config.options.watchOptions || {}) ); watcher.ready = false; var total = 0; watcher.on('change', filterAndRestart); watcher.on('unlink', filterAndRestart); watcher.on('add', function (file) { if (watcher.ready) { return filterAndRestart(file); } watchedFiles.push(file); bus.emit('watching', file); debug('chokidar watching: %s', file); }); watcher.on('ready', function () { watchedFiles = Array.from(new Set(watchedFiles)); // ensure no dupes total = watchedFiles.length; watcher.ready = true; resolve(total); debugRoot('watch is complete'); }); watcher.on('error', function (error) { if (error.code === 'EINVAL') { utils.log.error( 'Internal watch failed. Likely cause: too many ' + 'files being watched (perhaps from the root of a drive?\n' + 'See https://github.com/paulmillr/chokidar/issues/229 for details' ); } else { utils.log.error('Internal watch failed: ' + error.message); process.exit(1); } }); watchers.push(watcher); }); return promise.catch(e => { // this is a core error and it should break nodemon - so I have to break // out of a promise using the setTimeout setTimeout(() => { throw e; }); }).then(function () { utils.log.detail(`watching ${watchedFiles.length} file${ watchedFiles.length === 1 ? '' : 's'}`); return watchedFiles; }); } function filterAndRestart(files) { if (!Array.isArray(files)) { files = [files]; } if (files.length) { var cwd = process.cwd(); if (this.options && this.options.cwd) { cwd = this.options.cwd; } utils.log.detail( 'files triggering change check: ' + files .map(file => { const res = path.relative(cwd, file); return res; }) .join(', ') ); // make sure the path is right and drop an empty // filenames (sometimes on windows) files = files.filter(Boolean).map(file => { return path.relative(process.cwd(), path.relative(cwd, file)); }); if (utils.isWindows) { // ensure the drive letter is in uppercase (c:\foo -> C:\foo) files = files.map(f => { if (f.indexOf(':') === -1) { return f; } return f[0].toUpperCase() + f.slice(1); }); } debug('filterAndRestart on', files); var matched = match( files, config.options.monitor, undefsafe(config, 'options.execOptions.ext') ); debug('matched?', JSON.stringify(matched)); // if there's no matches, then test to see if the changed file is the // running script, if so, let's allow a restart if (config.options.execOptions && config.options.execOptions.script) { const script = path.resolve(config.options.execOptions.script); if (matched.result.length === 0 && script) { const length = script.length; files.find(file => { if (file.substr(-length, length) === script) { matched = { result: [file], total: 1, }; return true; } }); } } utils.log.detail( 'changes after filters (before/after): ' + [files.length, matched.result.length].join('/') ); // reset the last check so we're only looking at recently modified files config.lastStarted = Date.now(); if (matched.result.length) { if (config.options.delay > 0) { utils.log.detail('delaying restart for ' + config.options.delay + 'ms'); if (debouncedBus === undefined) { debouncedBus = debounce(restartBus, config.options.delay); } debouncedBus(matched); } else { return restartBus(matched); } } } } function restartBus(matched) { utils.log.status('restarting due to changes...'); matched.result.map(file => { utils.log.detail(path.relative(process.cwd(), file)); }); if (config.options.verbose) { utils.log._log(''); } bus.emit('restart', matched.result); } function debounce(fn, delay) { var timer = null; return function () { const context = this; const args = arguments; clearTimeout(timer); timer = setTimeout(() =>fn.apply(context, args), delay); }; } ================================================ FILE: lib/nodemon.js ================================================ var debug = require('debug')('nodemon'); var path = require('path'); var monitor = require('./monitor'); var cli = require('./cli'); var version = require('./version'); var util = require('util'); var utils = require('./utils'); var bus = utils.bus; var help = require('./help'); /** @type {import('..').NodemonEventConfig} */ var config = require('./config'); var spawn = require('./spawn'); const defaults = require('./config/defaults') var eventHandlers = {}; // this is fairly dirty, but theoretically sound since it's part of the // stable module API config.required = utils.isRequired; /** * @param {import('..').NodemonSettings | string} settings * @returns {import('..').Nodemon} */ function nodemon(settings) { bus.emit('boot'); nodemon.reset(); /** @type {import('..').NodemonSettings} */ let options // allow the cli string as the argument to nodemon, and allow for // `node nodemon -V app.js` or just `-V app.js` if (typeof settings === 'string') { settings = settings.trim(); if (settings.indexOf('node') !== 0) { if (settings.indexOf('nodemon') !== 0) { settings = 'nodemon ' + settings; } settings = 'node ' + settings; } options = cli.parse(settings); } else options = settings; // set the debug flag as early as possible to get all the detailed logging if (options.verbose) { utils.debug = true; } if (options.help) { if (process.stdout.isTTY) { process.stdout._handle.setBlocking(true); // nodejs/node#6456 } console.log(help(options.help)); if (!config.required) { process.exit(0); } } if (options.version) { version().then(function (v) { console.log(v); if (!config.required) { process.exit(0); } }); return; } // nodemon tools like grunt-nodemon. This affects where // the script is being run from, and will affect where // nodemon looks for the nodemon.json files if (options.cwd) { // this is protection to make sure we haven't dont the chdir already... // say like in cli/parse.js (which is where we do this once already!) if (process.cwd() !== path.resolve(config.system.cwd, options.cwd)) { process.chdir(options.cwd); } } config.load(options, function (config) { if (!config.options.dump && !config.options.execOptions.script && config.options.execOptions.exec === 'node') { if (!config.required) { console.log(help('usage')); process.exit(); } return; } // before we print anything, update the colour setting on logging utils.colours = config.options.colours; // always echo out the current version utils.log.info(version.pinned); const cwd = process.cwd(); if (config.options.cwd) { utils.log.detail('process root: ' + cwd); } config.loaded.map(file => file.replace(cwd, '.')).forEach(file => { utils.log.detail('reading config ' + file); }); if (config.options.stdin && config.options.restartable) { // allow nodemon to restart when the use types 'rs\n' process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.on('data', data => { const str = data.toString().trim().toLowerCase(); // if the keys entered match the restartable value, then restart! if (str === config.options.restartable) { bus.emit('restart'); } else if (data.charCodeAt(0) === 12) { // ctrl+l console.clear(); } }); } else if (config.options.stdin) { // so let's make sure we don't eat the key presses // but also, since we're wrapping, watch out for // special keys, like ctrl+c x 2 or '.exit' or ctrl+d or ctrl+l var ctrlC = false; var buffer = ''; process.stdin.on('data', function (data) { data = data.toString(); buffer += data; const chr = data.charCodeAt(0); // if restartable, echo back if (chr === 3) { if (ctrlC) { process.exit(0); } ctrlC = true; return; } else if (buffer === '.exit' || chr === 4) { // ctrl+d process.exit(); } else if (chr === 13 || chr === 10) { // enter / carriage return buffer = ''; } else if (chr === 12) { // ctrl+l console.clear(); buffer = ''; } ctrlC = false; }); if (process.stdin.setRawMode) { process.stdin.setRawMode(true); } } if (config.options.restartable) { utils.log.info('to restart at any time, enter `' + config.options.restartable + '`'); } if (!config.required) { const restartSignal = config.options.signal === 'SIGUSR2' ? 'SIGHUP' : 'SIGUSR2'; process.on(restartSignal, nodemon.restart); utils.bus.on('error', () => { utils.log.fail((new Error().stack)); }); utils.log.detail((config.options.restartable ? 'or ' : '') + 'send ' + restartSignal + ' to ' + process.pid + ' to restart'); } const ignoring = config.options.monitor.map(function (rule) { if (rule.slice(0, 1) !== '!') { return false; } rule = rule.slice(1); // don't notify of default ignores if (defaults.ignoreRoot.indexOf(rule) !== -1) { return false; // return rule.slice(3).slice(0, -3); } if (rule.startsWith(cwd)) { return rule.replace(cwd, '.'); } return rule; }).filter(Boolean).join(' '); if (ignoring) utils.log.detail('ignoring: ' + ignoring); utils.log.info('watching path(s): ' + config.options.monitor.map(function (rule) { if (rule.slice(0, 1) !== '!') { try { rule = path.relative(process.cwd(), rule); } catch (e) {} return rule; } return false; }).filter(Boolean).join(' ')); utils.log.info('watching extensions: ' + (config.options.execOptions.ext || '(all)')); if (config.options.dump) { utils.log._log('log', '--------------'); utils.log._log('log', 'node: ' + process.version); utils.log._log('log', 'nodemon: ' + version.pinned); utils.log._log('log', 'command: ' + process.argv.join(' ')); utils.log._log('log', 'cwd: ' + cwd); utils.log._log('log', ['OS:', process.platform, process.arch].join(' ')); utils.log._log('log', '--------------'); utils.log._log('log', util.inspect(config, { depth: null })); utils.log._log('log', '--------------'); if (!config.required) { process.exit(); } return; } config.run = true; if (config.options.stdout === false) { nodemon.on('start', function () { nodemon.stdout = bus.stdout; nodemon.stderr = bus.stderr; bus.emit('readable'); }); } if (config.options.events && Object.keys(config.options.events).length) { Object.keys(config.options.events).forEach(function (key) { utils.log.detail('bind ' + key + ' -> `' + config.options.events[key] + '`'); nodemon.on(key, function () { if (config.options && config.options.events) { spawn(config.options.events[key], config, [].slice.apply(arguments)); } }); }); } monitor.run(config.options); }); return nodemon; } nodemon.restart = function () { utils.log.status('restarting child process'); bus.emit('restart'); return nodemon; }; nodemon.addListener = nodemon.on = function (event, handler) { if (!eventHandlers[event]) { eventHandlers[event] = []; } eventHandlers[event].push(handler); bus.on(event, handler); return nodemon; }; nodemon.once = function (event, handler) { if (!eventHandlers[event]) { eventHandlers[event] = []; } eventHandlers[event].push(handler); bus.once(event, function () { debug('bus.once(%s)', event); eventHandlers[event].splice(eventHandlers[event].indexOf(handler), 1); handler.apply(this, arguments); }); return nodemon; }; nodemon.emit = function () { bus.emit.apply(bus, [].slice.call(arguments)); return nodemon; }; nodemon.removeAllListeners = function (event) { // unbind only the `nodemon.on` event handlers Object.keys(eventHandlers).filter(function (e) { return event ? e === event : true; }).forEach(function (event) { eventHandlers[event].forEach(function (handler) { bus.removeListener(event, handler); eventHandlers[event].splice(eventHandlers[event].indexOf(handler), 1); }); }); return nodemon; }; nodemon.reset = function (done) { bus.emit('reset', done); }; bus.on('reset', function (done) { debug('reset'); nodemon.removeAllListeners(); monitor.run.kill(true, function () { utils.reset(); config.reset(); config.run = false; if (done) { done(); } }); }); // expose the full config nodemon.config = config; module.exports = nodemon; ================================================ FILE: lib/rules/add.js ================================================ 'use strict'; var utils = require('../utils'); // internal var reEscComments = /\\#/g; // note that '^^' is used in place of escaped comments var reUnescapeComments = /\^\^/g; var reComments = /#.*$/; var reEscapeChars = /[.|\-[\]()\\]/g; var reAsterisk = /\*/g; module.exports = add; /** * Converts file patterns or regular expressions to nodemon * compatible RegExp matching rules. Note: the `rules` argument * object is modified to include the new rule and new RegExp * * ### Example: * * var rules = { watch: [], ignore: [] }; * add(rules, 'watch', '*.js'); * add(rules, 'ignore', '/public/'); * add(rules, 'watch', ':(\d)*\.js'); // note: string based regexp * add(rules, 'watch', /\d*\.js/); * * @param {Object} rules containing `watch` and `ignore`. Also updated during * execution * @param {String} which must be either "watch" or "ignore" * @param {String|RegExp} rule the actual rule. */ function add(rules, which, rule) { if (!{ ignore: 1, watch: 1}[which]) { throw new Error('rules/index.js#add requires "ignore" or "watch" as the ' + 'first argument'); } if (Array.isArray(rule)) { rule.forEach(function (rule) { add(rules, which, rule); }); return; } // support the rule being a RegExp, but reformat it to // the custom : format that we're working with. if (rule instanceof RegExp) { // rule = ':' + rule.toString().replace(/^\/(.*?)\/$/g, '$1'); utils.log.error('RegExp format no longer supported, but globs are.'); return; } // remove comments and trim lines // this mess of replace methods is escaping "\#" to allow for emacs temp files // first up strip comments and remove blank head or tails rule = (rule || '').replace(reEscComments, '^^') .replace(reComments, '') .replace(reUnescapeComments, '#').trim(); var regexp = false; if (typeof rule === 'string' && rule.substring(0, 1) === ':') { rule = rule.substring(1); utils.log.error('RegExp no longer supported: ' + rule); regexp = true; } else if (rule.length === 0) { // blank line (or it was a comment) return; } if (regexp) { // rules[which].push(rule); } else { // rule = rule.replace(reEscapeChars, '\\$&') // .replace(reAsterisk, '.*'); rules[which].push(rule); // compile a regexp of all the rules for this ignore or watch var re = rules[which].map(function (rule) { return rule.replace(reEscapeChars, '\\$&') .replace(reAsterisk, '.*'); }).join('|'); // used for the directory matching rules[which].re = new RegExp(re); } } ================================================ FILE: lib/rules/index.js ================================================ 'use strict'; var utils = require('../utils'); var add = require('./add'); var parse = require('./parse'); // exported var rules = { ignore: [], watch: [] }; /** * Loads a nodemon config file and populates the ignore * and watch rules with it's contents, and calls callback * with the new rules * * @param {String} filename * @param {Function} callback */ function load(filename, callback) { parse(filename, function (err, result) { if (err) { // we should have bombed already, but utils.log.error(err); callback(err); } if (result.raw) { result.raw.forEach(add.bind(null, rules, 'ignore')); } else { result.ignore.forEach(add.bind(null, rules, 'ignore')); result.watch.forEach(add.bind(null, rules, 'watch')); } callback(null, rules); }); } module.exports = { reset: function () { // just used for testing rules.ignore.length = rules.watch.length = 0; delete rules.ignore.re; delete rules.watch.re; }, load: load, ignore: { test: add.bind(null, rules, 'ignore'), add: add.bind(null, rules, 'ignore'), }, watch: { test: add.bind(null, rules, 'watch'), add: add.bind(null, rules, 'watch'), }, add: add.bind(null, rules), rules: rules, }; ================================================ FILE: lib/rules/parse.js ================================================ 'use strict'; var fs = require('fs'); /** * Parse the nodemon config file, supporting both old style * plain text config file, and JSON version of the config * * @param {String} filename * @param {Function} callback */ function parse(filename, callback) { var rules = { ignore: [], watch: [], }; fs.readFile(filename, 'utf8', function (err, content) { if (err) { return callback(err); } var json = null; try { json = JSON.parse(content); } catch (e) {} if (json !== null) { rules = { ignore: json.ignore || [], watch: json.watch || [], }; return callback(null, rules); } // otherwise return the raw file return callback(null, { raw: content.split(/\n/) }); }); } module.exports = parse; ================================================ FILE: lib/spawn.js ================================================ const path = require('path'); const utils = require('./utils'); const merge = utils.merge; const bus = utils.bus; const spawn = require('child_process').spawn; module.exports = function spawnCommand(command, config, eventArgs) { var stdio = ['pipe', 'pipe', 'pipe']; if (config.options.stdout) { stdio = ['pipe', process.stdout, process.stderr]; } const env = merge(process.env, { FILENAME: eventArgs[0] }); var sh = 'sh'; var shFlag = '-c'; var spawnOptions = { env: merge(config.options.execOptions.env, env), stdio: stdio, }; if (!Array.isArray(command)) { command = [command]; } if (utils.isWindows) { // if the exec includes a forward slash, reverse it for windows compat // but *only* apply to the first command, and none of the arguments. // ref #1251 and #1236 command = command.map(executable => { if (executable.indexOf('/') === -1) { return executable; } return executable.split(' ').map((e, i) => { if (i === 0) { return path.normalize(e); } return e; }).join(' '); }); // taken from npm's cli: https://git.io/vNFD4 sh = process.env.comspec || 'cmd'; shFlag = '/d /s /c'; spawnOptions.windowsVerbatimArguments = true; spawnOptions.windowsHide = true; } const args = command.join(' '); const child = spawn(sh, [shFlag, args], spawnOptions); if (config.required) { var emit = { stdout: function (data) { bus.emit('stdout', data); }, stderr: function (data) { bus.emit('stderr', data); }, }; // now work out what to bind to... if (config.options.stdout) { child.on('stdout', emit.stdout).on('stderr', emit.stderr); } else { child.stdout.on('data', emit.stdout); child.stderr.on('data', emit.stderr); bus.stdout = child.stdout; bus.stderr = child.stderr; } } }; ================================================ FILE: lib/utils/bus.js ================================================ var events = require('events'); var debug = require('debug')('nodemon'); var util = require('util'); var Bus = function () { events.EventEmitter.call(this); }; util.inherits(Bus, events.EventEmitter); var bus = new Bus(); // /* var collected = {}; bus.on('newListener', function (event) { debug('bus new listener: %s (%s)', event, bus.listeners(event).length); if (!collected[event]) { collected[event] = true; bus.on(event, function () { debug('bus emit: %s', event); }); } }); // */ // proxy process messages (if forked) to the bus process.on('message', function (event) { debug('process.message(%s)', event); bus.emit(event); }); var emit = bus.emit; // if nodemon was spawned via a fork, allow upstream communication // via process.send if (process.send) { bus.emit = function (event, data) { process.send({ type: event, data: data }); emit.apply(bus, arguments); }; } module.exports = bus; ================================================ FILE: lib/utils/clone.js ================================================ module.exports = clone; // via http://stackoverflow.com/a/728694/22617 function clone(obj) { // Handle the 3 simple types, and null or undefined if (null === obj || 'object' !== typeof obj) { return obj; } var copy; // Handle Date if (obj instanceof Date) { copy = new Date(); copy.setTime(obj.getTime()); return copy; } // Handle Array if (obj instanceof Array) { copy = []; for (var i = 0, len = obj.length; i < len; i++) { copy[i] = clone(obj[i]); } return copy; } // Handle Object if (obj instanceof Object) { copy = {}; for (var attr in obj) { if (obj.hasOwnProperty && obj.hasOwnProperty(attr)) { copy[attr] = clone(obj[attr]); } } return copy; } throw new Error('Unable to copy obj! Its type isn\'t supported.'); } ================================================ FILE: lib/utils/colour.js ================================================ /** * Encodes a string in a colour: red, yellow or green * @param {String} c colour to highlight in * @param {String} str the string to encode * @return {String} coloured string for terminal printing */ function colour(c, str) { return (colour[c] || colour.black) + str + colour.black; } function strip(str) { re.lastIndex = 0; // reset position return str.replace(re, ''); } colour.red = '\x1B[31m'; colour.yellow = '\x1B[33m'; colour.green = '\x1B[32m'; colour.black = '\x1B[39m'; var reStr = Object.keys(colour).map(key => colour[key]).join('|'); var re = new RegExp(('(' + reStr + ')').replace(/\[/g, '\\['), 'g'); colour.strip = strip; module.exports = colour; ================================================ FILE: lib/utils/index.js ================================================ var noop = function () { }; var path = require('path'); const semver = require('semver'); var version = process.versions.node.split('.') || [null, null, null]; var utils = (module.exports = { semver: semver, satisfies: test => semver.satisfies(process.versions.node, test), version: { major: parseInt(version[0] || 0, 10), minor: parseInt(version[1] || 0, 10), patch: parseInt(version[2] || 0, 10), }, clone: require('./clone'), merge: require('./merge'), bus: require('./bus'), isWindows: process.platform === 'win32', isMac: process.platform === 'darwin', isLinux: process.platform === 'linux', isIBMi: require('os').type() === 'OS400', isRequired: (function () { var p = module.parent; while (p) { // in electron.js engine it happens if (!p.filename) { return true; } if (p.filename.indexOf('bin' + path.sep + 'nodemon.js') !== -1) { return false; } p = p.parent; } return true; })(), home: process.env.HOME || process.env.HOMEPATH, quiet: function () { // nukes the logging if (!this.debug) { for (var method in utils.log) { if (typeof utils.log[method] === 'function') { utils.log[method] = noop; } } } }, reset: function () { if (!this.debug) { for (var method in utils.log) { if (typeof utils.log[method] === 'function') { delete utils.log[method]; } } } this.debug = false; }, regexpToText: function (t) { return t .replace(/\.\*\\./g, '*.') .replace(/\\{2}/g, '^^') .replace(/\\/g, '') .replace(/\^\^/g, '\\'); }, stringify: function (exec, args) { // serializes an executable string and array of arguments into a string args = args || []; return [exec] .concat( args.map(function (arg) { // if an argument contains a space, we want to show it with quotes // around it to indicate that it is a single argument if (arg.length > 0 && arg.indexOf(' ') === -1) { return arg; } // this should correctly escape nested quotes return JSON.stringify(arg); }) ) .join(' ') .trim(); }, }); utils.log = require('./log')(utils.isRequired); Object.defineProperty(utils, 'debug', { set: function (value) { this.log.debug = value; }, get: function () { return this.log.debug; }, }); Object.defineProperty(utils, 'colours', { set: function (value) { this.log.useColours = value; }, get: function () { return this.log.useColours; }, }); ================================================ FILE: lib/utils/log.js ================================================ var colour = require('./colour'); var bus = require('./bus'); var required = false; var useColours = true; var coding = { log: 'black', info: 'yellow', status: 'green', detail: 'yellow', fail: 'red', error: 'red', }; function log(type, text) { var msg = '[nodemon] ' + (text || ''); if (useColours) { msg = colour(coding[type], msg); } // always push the message through our bus, using nextTick // to help testing and get _out of_ promises. process.nextTick(() => { bus.emit('log', { type: type, message: text, colour: msg }); }); // but if we're running on the command line, also echo out // question: should we actually just consume our own events? if (!required) { if (type === 'error') { console.error(msg); } else { console.log(msg || ''); } } } var Logger = function (r) { if (!(this instanceof Logger)) { return new Logger(r); } this.required(r); return this; }; Object.keys(coding).forEach(function (type) { Logger.prototype[type] = log.bind(null, type); }); // detail is for messages that are turned on during debug Logger.prototype.detail = function (msg) { if (this.debug) { log('detail', msg); } }; Logger.prototype.required = function (val) { required = val; }; Logger.prototype.debug = false; Logger.prototype._log = function (type, msg) { if (required) { bus.emit('log', { type: type, message: msg || '', colour: msg || '' }); } else if (type === 'error') { console.error(msg); } else { console.log(msg || ''); } }; Object.defineProperty(Logger.prototype, 'useColours', { set: function (val) { useColours = val; }, get: function () { return useColours; }, }); module.exports = Logger; ================================================ FILE: lib/utils/merge.js ================================================ var clone = require('./clone'); module.exports = merge; function typesMatch(a, b) { return (typeof a === typeof b) && (Array.isArray(a) === Array.isArray(b)); } /** * A deep merge of the source based on the target. * @param {Object} source [description] * @param {Object} target [description] * @return {Object} [description] */ function merge(source, target, result) { if (result === undefined) { result = clone(source); } // merge missing values from the target to the source Object.getOwnPropertyNames(target).forEach(function (key) { if (source[key] === undefined) { result[key] = target[key]; } }); Object.getOwnPropertyNames(source).forEach(function (key) { var value = source[key]; if (target[key] && typesMatch(value, target[key])) { // merge empty values if (value === '') { result[key] = target[key]; } if (Array.isArray(value)) { if (value.length === 0 && target[key].length) { result[key] = target[key].slice(0); } } else if (typeof value === 'object') { result[key] = merge(value, target[key]); } } }); return result; } ================================================ FILE: lib/version.js ================================================ module.exports = version; module.exports.pin = pin; var fs = require('fs'); var path = require('path'); var exec = require('child_process').exec; var root = null; function pin() { return version().then(function (v) { version.pinned = v; }); } function version(callback) { // first find the package.json as this will be our root var promise = findPackage(path.dirname(module.parent.filename)) .then(function (dir) { // now try to load the package var v = require(path.resolve(dir, 'package.json')).version; if (v && v !== '0.0.0-development') { return v; } root = dir; // else we're in development, give the commit out // get the last commit and whether the working dir is dirty var promises = [ branch().catch(function () { return 'master'; }), commit().catch(function () { return ''; }), dirty().catch(function () { return 0; }), ]; // use the cached result as the export return Promise.all(promises).then(function (res) { var branch = res[0]; var commit = res[1]; var dirtyCount = parseInt(res[2], 10); var curr = branch + ': ' + commit; if (dirtyCount !== 0) { curr += ' (' + dirtyCount + ' dirty files)'; } return curr; }); }).catch(function (error) { console.log(error.stack); throw error; }); if (callback) { promise.then(function (res) { callback(null, res); }, callback); } return promise; } function findPackage(dir) { if (dir === '/') { return Promise.reject(new Error('package not found')); } return new Promise(function (resolve) { fs.stat(path.resolve(dir, 'package.json'), function (error, exists) { if (error || !exists) { return resolve(findPackage(path.resolve(dir, '..'))); } resolve(dir); }); }); } function command(cmd) { return new Promise(function (resolve, reject) { exec(cmd, { cwd: root }, function (err, stdout, stderr) { var error = stderr.trim(); if (error) { return reject(new Error(error)); } resolve(stdout.split('\n').join('')); }); }); } function commit() { return command('git rev-parse HEAD'); } function branch() { return command('git rev-parse --abbrev-ref HEAD'); } function dirty() { return command('expr $(git status --porcelain 2>/dev/null| ' + 'egrep "^(M| M)" | wc -l)'); } ================================================ FILE: package.json ================================================ { "name": "nodemon", "homepage": "https://nodemon.io", "author": { "name": "Remy Sharp", "url": "https://github.com/remy" }, "bin": { "nodemon": "./bin/nodemon.js" }, "engines": { "node": ">=10" }, "repository": { "type": "git", "url": "https://github.com/remy/nodemon.git" }, "description": "Simple monitor script for use during development of a Node.js app.", "keywords": [ "cli", "monitor", "monitor", "development", "restart", "autoload", "reload", "terminal" ], "license": "MIT", "types": "./index.d.ts", "main": "./lib/nodemon", "scripts": { "commitmsg": "commitlint -e", "coverage": "istanbul cover _mocha -- --timeout 30000 --ui bdd --reporter list test/**/*.test.js", "lint": "eslint lib/**/*.js", "test": "npm run lint && npm run spec", "spec": "for FILE in test/**/*.test.js; do echo $FILE; TEST=1 mocha --exit --timeout 30000 $FILE; if [ $? -ne 0 ]; then exit 1; fi; sleep 1; done", "postspec": "npm run clean", "clean": "rm -rf test/fixtures/test*.js test/fixtures/test*.md", "web": "node web", "semantic-release": "semantic-release", "prepush": "npm run lint", "killall": "ps auxww | grep node | grep -v grep | awk '{ print $2 }' | xargs kill -9" }, "devDependencies": { "@commitlint/cli": "^11.0.0", "@commitlint/config-conventional": "^11.0.0", "async": "1.4.2", "coffee-script": "~1.7.1", "eslint": "^7.32.0", "husky": "^7.0.4", "mocha": "^2.5.3", "nyc": "^15.1.0", "proxyquire": "^1.8.0", "semantic-release": "^25.0.0", "should": "~4.0.0" }, "dependencies": { "chokidar": "^3.5.2", "debug": "^4", "ignore-by-default": "^1.0.1", "minimatch": "^10.2.1", "pstree.remy": "^1.1.8", "semver": "^7.5.3", "simple-update-notifier": "^2.0.0", "supports-color": "^5.5.0", "touch": "^3.1.0", "undefsafe": "^2.0.5" }, "version": "0.0.0-development", "funding": { "type": "opencollective", "url": "https://opencollective.com/nodemon" }, "publishConfig": { "provenance": true } } ================================================ FILE: test/cli/exec.test.js ================================================ 'use strict'; /*global describe:true, it: true */ const path = require('path'); const exec = require('../../lib/config/exec'); const expandScript = exec.expandScript; const command = require('../../lib/config/command'); const assert = require('assert'); const utils = require('../../lib/utils'); function toCmd(options) { var cmd = command({ script: options.script || 'app.js', execOptions: options, }); return { cmd: cmd, string: utils.stringify(cmd.executable, cmd.args), }; } describe('expandScript', () => { var pwd = process.cwd(); afterEach(function () { process.chdir(pwd); }); beforeEach(function () { // move to the fixtures directory to allow for config loading process.chdir(path.resolve(pwd, 'test/fixtures')); }); it('should expand app.js', () => { const script = expandScript('app'); assert.equal(script, 'app.js', script); }); it('should expand hello.py', () => { const script = expandScript('hello', '.py'); assert.equal(script, 'hello.py', script); }); it('should ignore foo.js', () => { const script = expandScript('foo', '.js'); assert.equal(script, 'foo', script); }); }); describe('nodemon exec', function () { var pwd = process.cwd(); afterEach(function () { process.chdir(pwd); }); beforeEach(function () { // move to the fixtures directory to allow for config loading process.chdir(path.resolve(pwd, 'test/fixtures')); }); it('should default to node', function () { var options = exec({ script: 'index.js' }); var cmd = toCmd(options); assert.equal(options.exec, 'node', 'exec is node'); assert.equal(options.ext, 'js,mjs,cjs,json'); assert.equal(cmd.string, 'node index.js', cmd.string); }); it('should support --debug', function () { var options = exec({ script: 'app.js', nodeArgs: ['--debug'] }); var cmd = toCmd(options); assert(cmd.string === 'node --debug app.js', cmd.string); assert(options.ext.indexOf('js') !== -1, 'extension watched is .js'); }); it('should support --debug=XXXX', function () { var options = exec({ script: 'app.js', nodeArgs: ['--debug=9999'] }); var cmd = toCmd(options); assert(cmd.string === 'node --debug=9999 app.js', cmd.string); assert(options.exec === 'node'); assert(options.ext.indexOf('js') !== -1); }); it('should support multiple extensions', function () { var options = exec({ script: 'app.js', ext: 'js, pug, hbs' }); var cmd = toCmd(options); assert(cmd.string === 'node app.js', cmd.string); assert(options.ext.indexOf('pug') !== -1, 'comma separated string'); options = exec({ script: 'app.js', ext: 'js|pug|hbs' }); assert(options.exec === 'node'); assert(options.ext.indexOf('pug') !== -1, 'pipe separated string'); }); it('should support watching all extensions', function () { var options = exec({ script: 'app.js', ext: '' }); assert.equal( options.ext, '', 'does not set default extensions when empty extension requested' ); options = exec({ script: 'app.js', ext: '.' }); assert.equal(options.ext, '', 'treats `.` as wildcard extension'); options = exec({ script: 'app.js', ext: '*' }); assert.equal(options.ext, '', 'treats `*` as wildcard extension'); options = exec({ script: 'app.coffee', exec: 'coffee', ext: '' }); assert.equal( options.ext, '', 'does not set default extensions when empty extension requested' ); }); it('should replace {{filename}}', function () { var options = exec({ script: 'app.js', exec: 'node {{filename}}.tmp --somethingElse', }); var cmd = toCmd(options); assert(cmd.string === 'node app.js.tmp --somethingElse', cmd.string); }); it('should not split on spaces in {{filename}}', function () { var options = exec({ script: 'my app.js', exec: 'node {{filename}}.tmp --somethingElse', }); var cmd = toCmd(options); // var cmd = command({ execOptions: options }); assert(cmd.string === 'node my app.js.tmp --somethingElse', cmd.string); }); it('should support extension maps', function () { var options = exec( { script: 'template.pug' }, { pug: 'pug {{filename}} --out /tmp' } ); var cmd = toCmd(options); assert(cmd.string === 'pug template.pug --out /tmp', cmd.string); }); it('should support input from argv#parse', function () { var parse = require('../../lib/cli/parse'); parse( 'node /usr/local/bin/nodemon.js --debug -e js,pug,hbs app.js'.split(' ') ); }); it('should use coffeescript on .coffee', function () { var options = exec({ script: 'index.coffee' }); assert( options.exec.indexOf('coffee') === 0, 'using coffeescript to execute' ); assert(options.ext.indexOf('coffee') !== -1); }); it('should support coffeescript in debug mode', function () { var options = exec({ script: 'app.coffee', nodeArgs: ['--debug'] }); assert( options.exec.indexOf('coffee') === 0, 'using coffeescript to execute' ); assert(options.execArgs[1].indexOf('--debug') !== -1); assert(options.ext.indexOf('coffee') !== -1); }); it('should support custom execs', function () { var options = exec({ script: 'app.py', exec: 'python' }); assert(options.exec === 'python'); assert(options.ext.indexOf('py') !== -1); }); it('should support custom executables with arguments', function () { var options = exec({ script: 'app.py', exec: 'python --debug' }); var cmd = toCmd(options); assert(cmd.string === 'python --debug app.py', cmd.string); assert(options.ext.indexOf('py') !== -1); }); it('should support an array of exec arguments', function () { var options = exec({ script: 'app.js', exec: ['/path to node', '-v'] }); assert(options.exec === '/path to node', options.exec); assert(options.execArgs.length === 1, options.execArgs.length); assert(options.execArgs[0] === '-v', options.execArgs[0]); }); it('should support non-english filenames', function () { var parse = require('../../lib/cli/parse'); var options = parse('node nodemon.js -e ζ ./server.js "$@"'.split(' ')); var res = exec(options); assert(res.ext === 'ζ', 'exec did not bail'); }); it('should support multi-level file extensions', function () { var options = exec({ ext: '.ts.d,js md' }); assert(options.ext.indexOf('ts.d') !== -1); assert(options.ext.indexOf('js') !== -1); assert(options.ext.indexOf('md') !== -1); }); it('should support single-level file extensions', function () { var options = exec({ ext: '.js, pug' }); assert(options.ext.indexOf('js') !== -1); assert(options.ext.indexOf('pug') !== -1); }); it('should expand app to app.js', function () { var options = exec({ script: 'app' }); var cmd = toCmd(options); assert(cmd.string === 'node app.js', cmd.string); options = exec({ script: 'app', ext: '' }); cmd = toCmd(options); assert(cmd.string === 'node app.js', cmd.string); }); it('should expand based on custom extensions to hello.py', function () { var options = exec({ script: 'hello', ext: '.py', exec: 'python' }); var cmd = toCmd(options); assert(cmd.string === 'python hello.py', cmd.string); }); it('should expand based on custom extensions to app.js (js,jsx,mjs)', function () { var options = exec({ script: 'app', ext: 'js,jsx,mjs' }); var cmd = toCmd(options); assert(cmd.string === 'node app.js', cmd.string); }); it('should not expand index to non-existant index.js', function () { var options = exec({ script: 'index' }); var cmd = toCmd(options); assert(cmd.string === 'node index', cmd.string); }); }); ================================================ FILE: test/cli/parse.test.js ================================================ 'use strict'; /*global describe:true, it: true */ var cli = require('../../lib/cli/'), exec = require('../../lib/config/exec'), pkg = require('../../package'), assert = require('assert'), command = require('../../lib/config/command'), utils = require('../../lib/utils'); const mutateExecOptions = require('../../lib/config/load').mutateExecOptions; function asCLI(cmd) { return ('node nodemon ' + (cmd || '')).trim(); } function parse(cmd) { var parsed = cli.parse(cmd); // mirrored based on /lib/config/load.js:36 parsed.execOptions = exec({ script: parsed.script, exec: parsed.exec, args: parsed.args, scriptPosition: parsed.scriptPosition, nodeArgs: parsed.nodeArgs, ext: parsed.ext, env: parsed.env }); return parsed; return mutateExecOptions(cli.parse(cmd)); } function commandToString(command) { return utils.stringify(command.executable, command.args); } describe('nodemon CLI parser', function () { it('should support --debug with script detect via package', function () { var cwd = process.cwd(); process.chdir('test/fixtures/packages/express4'); var settings = parse(asCLI('--debug')); var cmd = commandToString(command(settings)); process.chdir(cwd); assert.equal(cmd, 'NODE_ENV=development node ./bin/www --debug'); }); it('should replace {{filename}}', function () { var settings = parse(asCLI('test/fixtures/app.js --exec "node {{filename}}.tmp" --somethingElse')); var cmd = commandToString(command(settings)); assert(cmd === 'node test/fixtures/app.js.tmp --somethingElse', cmd); }); it('should replace {{filename}} multiple times', function () { var settings = parse(asCLI('test/fixtures/app.js --exec "node {{filename}}.tmp {{filename}}.tmp" --somethingElse')); var cmd = commandToString(command(settings)); assert(cmd === 'node test/fixtures/app.js.tmp test/fixtures/app.js.tmp --somethingElse', cmd); }); it('should parse the help examples #1', function () { var settings = parse(asCLI('test/fixtures/app.js')), cmd = commandToString(command(settings)); assert(cmd === 'node test/fixtures/app.js', 'node test/fixtures/app.js: ' + cmd); }); it('should parse the help examples #2', function () { var settings = parse(asCLI('-w ../lib test/fixtures/app.js apparg1 apparg2')), cmd = commandToString(command(settings)); assert.deepEqual(settings.watch, ['../lib'], 'watching ../lib: ' + settings.watch); assert.deepEqual(settings.execOptions.args, ['apparg1', 'apparg2'], 'args are corr ' + settings.execOptions.args); assert(cmd === 'node test/fixtures/app.js apparg1 apparg2', 'command is ' + cmd); }); it('should parse the help examples #3', function () { var settings = parse(asCLI('--exec python app.py')), cmd = commandToString(command(settings)); assert(cmd === 'python app.py', 'command is ' + cmd); assert(settings.execOptions.exec === 'python', 'exec is python'); }); it('should parse the help examples #4', function () { var settings = parse(asCLI('--exec "make build" -e "styl hbs"')), cmd = commandToString(command(settings)); assert(cmd === 'make build', 'command is ' + cmd); assert.deepEqual(settings.execOptions.ext.split(','), ['styl', 'hbs'], 'correct extensions being watched: ' + settings.execOptions.ext); }); it('should parse the help examples #5', function () { var settings = parse(asCLI('test/fixtures/app.js -- -L')), cmd = commandToString(command(settings)); assert(cmd === 'node test/fixtures/app.js -L', 'command is ' + cmd); }); it('should put the script at the end if found in package.main', function () { var pwd = process.cwd(); process.chdir('test/fixtures'); // allows us to load text/fixtures/package.json var settings = parse(asCLI('--harmony')), cmd = commandToString(command(settings)); process.chdir(pwd); assert(cmd === 'node --harmony app.js', 'command is ' + cmd); }); it('should support default express4 format', function () { var pwd = process.cwd(); process.chdir('test/fixtures/packages/express4'); // allows us to load text/fixtures/package.json var settings = parse(asCLI()), cmd = commandToString(command(settings)); process.chdir(pwd); assert.equal(cmd, 'NODE_ENV=development node ./bin/www', 'command is "' + cmd + '"'); }); it('should support spaces', function () { var pwd = process.cwd(); process.chdir('test/fixtures/'); var settings = parse(asCLI('--exec \'"app with spaces.js" foo\'')); var cmd = commandToString(command(settings)); process.chdir(pwd); assert(cmd === '"app with spaces.js" foo', cmd); }); it('should support quotes around arguments', function () { var settings = parse(asCLI('--watch "foo bar"')); assert(settings.watch[0] === 'foo bar'); }); it('should keep eating arguments that are for nodemon after the script.js', function () { var settings = parse(asCLI('--watch "foo bar" test/fixtures/app.js -V --scriptOpt1 -- -V')); assert.deepEqual(settings.execOptions.args, ['--scriptOpt1', '-V'], 'script args are: ' + settings.execOptions.args.join(' ')); assert(settings.verbose === true, 'verbose'); assert(settings.watch[0] === 'foo bar', 'watching "foo bar" dir'); }); it('should allow -- to appear anywhere, and still find user script', function () { var settings = parse(asCLI('test/fixtures/app.js -- -V')); assert(!settings.verbose, '-V arg was passed to script, not nodemon'); assert.deepEqual(settings.execOptions.args, ['-V'], 'script passed -V via --'); settings = parse(asCLI('-- test/fixtures/app.js -V')); assert.deepEqual(settings.execOptions.args, ['-V'], 'leading -- finds script'); settings = parse(asCLI('test/fixtures/app.js -V --')); assert.deepEqual(settings.execOptions.args, [], '-- is ignored'); assert(settings.verbose, '-V was passed to nodemon'); }); it('should support arguments from the cli', function () { var settings = parse(['node', 'nodemon', '--watch', 'foo bar']); assert(settings.watch[0] === 'foo bar'); }); it('should support stand alone `nodemon` command', function () { var settings = parse(asCLI('')); assert(settings.execOptions.script === pkg.main + '.js', `${settings.execOptions.script} === ${pkg.main}`); }); it('should put --debug in the right place with coffescript', function () { var settings = parse(asCLI('--debug test/fixtures/app.coffee')); // using indexOf instead of === because on windows // coffee is coffee.cmd - so we check for a partial match assert(commandToString(command(settings)).indexOf('--nodejs --debug test/fixtures/app.coffee') !== -1); assert(settings.execOptions.exec.indexOf('coffee') === 0, 'executable is CoffeeScript'); }); it('should support period path', function () { var settings = parse(asCLI('.')); assert(commandToString(command(settings)) === 'node .'); }); it('should parse `nodemon lib/index.js`', function () { var settings = parse(asCLI('lib/index.js')); assert(settings.script === 'lib/index.js'); }); it('should parse `nodemon --config my/.nodemon.json server.js`', function () { var settings = parse(asCLI('--config my/.nodemon.json test/fixtures/app.js')); assert(settings.configFile === 'my/.nodemon.json'); assert(settings.script === 'test/fixtures/app.js'); }); it('should parse `nodemon test/fixtures/app.coffee`', function () { var settings = parse(asCLI('test/fixtures/app.coffee')); assert(settings.script === 'test/fixtures/app.coffee'); assert(settings.execOptions.exec.indexOf('coffee') === 0, 'executable is CoffeeScript'); }); it('should parse `nodemon --watch src/ -e js,coffee test/fixtures/app.js`', function () { var settings = parse(asCLI('--watch src/ -e js,coffee test/fixtures/app.js')); assert(settings.script === 'test/fixtures/app.js'); assert(settings.execOptions.exec === 'node'); }); it('should pass --debug to node', function () { var settings = parse(asCLI('--debug test/fixtures/app.js')); assert(settings.script === 'test/fixtures/app.js'); assert(settings.execOptions.exec === 'node'); assert(commandToString(command(settings)).indexOf('--debug') !== -1); }); it('should pass --harmony to node', function () { var settings = parse(asCLI('--harmony test/fixtures/app.js')); assert(settings.script === 'test/fixtures/app.js'); assert(settings.execOptions.exec === 'node'); assert(commandToString(command(settings)).indexOf('--harmony') !== -1); }); }); describe('nodemon argument parser', function () { it('support strings', function () { var settings = cli.parse('node nodemon -v'); assert(settings.version === true, 'version flag'); }); it('should support short versions of flags', function () { var settings = cli.parse('node nodemon -v -x java -I -V -q -w fixtures -i fixtures -d 5 -L -C -e pug -s SIGHUP'); assert(settings.version, 'version'); assert(settings.verbose, 'verbose'); assert(settings.exec === 'java', 'exec'); assert(settings.quiet, 'quiet'); assert(settings.stdin === false, 'read stdin'); assert(settings.watch[0] === 'fixtures', 'watch'); assert(settings.ignore[0] === 'fixtures', 'ignore'); assert(settings.delay === 5000, 'delay 5 seconds'); assert(settings.runOnChangeOnly, 'run on change only'); assert(settings.ext === 'pug', 'extension is pug'); assert(settings.signal === 'SIGHUP', 'signal is SIGHUP'); }); it('should support long versions of flags', function () { var settings = cli.parse('node nodemon --version --exec java --verbose --quiet --watch fixtures --ignore fixtures --no-stdin --delay 5 --legacy-watch --exitcrash --on-change-only --ext pug --config my/.nodemon.json --signal SIGHUP'); assert(settings.version, 'version'); assert(settings.verbose, 'verbose'); assert(settings.exec === 'java', 'exec'); assert(settings.quiet, 'quiet'); assert(settings.stdin === false, 'read stdin'); assert(settings.exitCrash, 'exit if crash'); assert(settings.watch[0] === 'fixtures', 'watch'); assert(settings.ignore[0] === 'fixtures', 'ignore'); assert(settings.delay === 5000, 'delay 5 seconds'); assert(settings.runOnChangeOnly, 'run on change only'); assert(settings.ext === 'pug', 'extension is pug'); assert(settings.configFile === 'my/.nodemon.json', 'custom config file name is my/.nodemon.json'); assert(settings.signal === 'SIGHUP', 'signal is SIGHUP'); }); }); describe('nodemon respects custom "ext" and "execMap"', function () { it('should support "ext" and "execMap" for same extension', function () { var settings = parse(asCLI('-x "node --harmony" -e "js json coffee" test/fixtures/app.coffee')); assert(settings.execOptions.ext.indexOf('js') === 0, 'js is monitored: ' + settings.execOptions.ext); assert(settings.execOptions.ext.split(',').length === 3, 'all extensions monitored'); assert(settings.execOptions.exec.indexOf('node') === 0, 'node is exec: ' + settings.execOptions.exec); }); }); describe('nodemon should support implicit extensions', () => { it('should expand script to script.js', () => { const cwd = process.cwd(); process.chdir('test/fixtures/'); const settings = parse(asCLI('env')); process.chdir(cwd); var cmd = commandToString(command(settings)); assert.equal(cmd, 'node env.js', 'implicit extension added'); }); it('should support non-js', () => { const cwd = process.cwd(); process.chdir('test/fixtures/'); const settings = parse(asCLI('hello --ext py')); process.chdir(cwd); var cmd = commandToString(command(settings)); assert.equal(cmd, 'node hello.py', 'implicit extension added'); }); }); describe('nodemon should slurp properly', () => { it('should read quotes as a single entity', () => { const settings = parse(asCLI('notindex.js -- -b "hello - world"')); assert(settings.execOptions.exec === 'node', 'node is exec'); assert(settings.args.length === 3, 'only has 3 arguments to node'); }); it('should pass non-slurped args to script', () => { const settings = parse(asCLI('-- --log')); var cmd = commandToString(command(settings)); assert.equal(cmd, 'node ./lib/nodemon.js --log', 'args passed to script'); }); it('should pass non-slurped args to explicit script', () => { const settings = parse(asCLI('./lib/nodemon.js -- --log')); var cmd = commandToString(command(settings)); assert.equal(cmd, 'node ./lib/nodemon.js --log', 'args passed to script'); }); it('should pass slurped args to explicit script', () => { const settings = parse(asCLI('./lib/nodemon.js --log')); var cmd = commandToString(command(settings)); assert.equal(cmd, 'node ./lib/nodemon.js --log', 'args passed to script'); }); it('should handle a mix of slurps', () => { var cmd; var settings; cmd = commandToString(command(parse(asCLI('--inspect -- --log')))); assert.equal(cmd, 'node --inspect ./lib/nodemon.js --log', 'args passed to script'); cmd = commandToString(command(parse(asCLI('--inspect ./lib/nodemon.js -- --log')))); assert.equal(cmd, 'node --inspect ./lib/nodemon.js --log', 'args passed to script'); cmd = commandToString(command(parse(asCLI('--inspect --log ./lib/nodemon.js')))); assert.equal(cmd, 'node --inspect --log ./lib/nodemon.js', 'args passed to script'); }); }); describe('nodemon with CoffeeScript', function () { it('should not add --nodejs by default', function () { var settings = parse(asCLI('test/fixtures/app.coffee')); assert(settings.execOptions.exec.indexOf('coffee') === 0, 'executable is CoffeeScript'); assert(settings.execOptions.execArgs.indexOf('--nodejs') === -1, 'is not using --nodejs'); }); it('should not add --nodejs with app arguments', function () { var settings = parse(asCLI('test/fixtures/app.coffee --my-app-arg')); assert(settings.execOptions.exec.indexOf('coffee') === 0, 'executable is CoffeeScript'); assert(settings.execOptions.execArgs.indexOf('--nodejs') === -1, 'is not using --nodejs'); }); it('groups exec argument into a single --nodejs argument', function () { var settings = parse(asCLI('--harmony --debug test/fixtures/app.coffee')); assert(settings.execOptions.exec.indexOf('coffee') === 0, 'executable is CoffeeScript'); assert(settings.execOptions.execArgs[0] === '--nodejs', 'is using --nodejs'); assert(settings.execOptions.execArgs[1] === '--harmony --debug', 'is grouping exec arguments'); }); it('should add --nodejs when used with --debug', function () { var settings = parse(asCLI('--debug test/fixtures/app.coffee')); var cmd = commandToString(command(settings)); assert(settings.execOptions.exec.indexOf('coffee') === 0, 'executable is CoffeeScript'); assert(cmd.indexOf('--nodejs') !== -1, '--nodejs being used'); assert(cmd.indexOf('--debug') !== -1, '--debug being used'); }); it('should add --nodejs when used with --debug-brk', function () { var settings = parse(asCLI('--debug-brk test/fixtures/app.coffee')); var cmd = commandToString(command(settings)); assert(settings.execOptions.exec.indexOf('coffee') === 0, 'executable is CoffeeScript'); assert(cmd.indexOf('--nodejs') !== -1, '--nodejs being used'); assert(cmd.indexOf('--debug-brk') !== -1, '--debug-brk being used'); }); }); describe('nodemon --delay argument', function () { it('should support an integer value', function () { var settings = cli.parse('node nodemon --delay 5'); assert(settings.delay === 5000, 'delay 5 seconds'); }); it('should support a float value', function () { var settings = cli.parse('node nodemon --delay 1.2'); assert(settings.delay === 1200, 'delay 1.2 seconds'); }); it('should support a value with a time specifier for seconds (s)', function () { var settings = cli.parse('node nodemon --delay 5s'); assert(settings.delay === 5000, 'delay 5 seconds'); }); it('should support a value with a time specifier for milliseconds (ms)', function () { var settings = cli.parse('node nodemon --delay 1200ms'); assert(settings.delay === 1200, 'delay 1.2 seconds'); }); }); ================================================ FILE: test/config/env.test.js ================================================ 'use strict'; /*global describe:true, it: true, after: true */ var nodemon = require('../../lib/'), path = require('path'), assert = require('assert'); describe('when nodemon runs (1)', function () { var tmp = path.resolve('test/fixtures/env.js'); after(function (done) { // clean up just in case. nodemon .once('exit', function () { nodemon.reset(done); }) .emit('quit'); }); it('should pass through environment values', function (done) { nodemon({ script: tmp, stdout: false, env: { NODEMON_ENV: 'nodemon' } }).on( 'stdout', function (data) { assert( data.toString().trim() === 'nodemon', 'NODEMON_ENV env value correctly set to "nodemon": ' + data.toString() ); nodemon .once('exit', function () { nodemon.reset(done); }) .emit('quit'); } ); }); }); ================================================ FILE: test/config/load-logging.test.js ================================================ 'use strict'; /*global describe, it, afterEach, beforeEach, after */ const load = require('../../lib/config/load'); const utils = require('../../lib/utils'); const path = require('path'); const testUtils = require('../utils'); const assert = require('assert'); const noop = {}; describe('config logging', () => { const pwd = process.cwd(); const oldHome = utils.home; beforeEach(() => { // move to the fixtures directory to allow for config loading process.chdir(path.resolve(pwd, 'test/fixtures')); utils.home = path.resolve( pwd, ['test', 'fixtures', 'global'].join(path.sep) ); }); afterEach(() => { process.chdir(pwd); utils.home = oldHome; }); it('should show package is being used', (done) => { process.chdir( path.resolve(pwd, 'test/fixtures/packages/package-json-settings') ); const config = {}; load(noop, noop, config, () => { assert.equal(config.loaded.length, 2, 'global nodemon and local package'); done(); }); }); it('should not read package if no nodemonConfig', (done) => { utils.home = process.cwd(); process.chdir(path.resolve(pwd, 'test/fixtures')); const config = {}; load(noop, noop, config, () => { const files = config.loaded.map((_) => path.relative(pwd, _)); assert.equal(files.length, 1, 'global nodemon'); assert.deepEqual(files, ['test/fixtures/nodemon.json'], 'global nodemon'); done(); }); }); it('should ignore legacy if new format is found', (done) => { utils.home = process.cwd(); process.chdir(path.resolve(pwd, 'test/fixtures/legacy')); const config = {}; load(noop, noop, config, () => { const loaded = config.loaded.map((_) => path.relative(pwd, _)); assert.equal( loaded.length, 1, 'global nodemon is loaded and legacy is ignored' ); done(); }); }); it('should load nothing if nothing found', (done) => { utils.home = path.resolve(pwd, 'test/fixtures/configs'); // no valid nodemon.json files process.chdir(pwd); const config = {}; load(noop, noop, config, () => { const loaded = config.loaded.map((_) => path.relative(pwd, _)); assert.deepEqual(loaded, [], 'nothing loaded'); done(); }); }); }); ================================================ FILE: test/config/load.test.js ================================================ 'use strict'; /*global describe, it, afterEach, beforeEach, after */ var load = require('../../lib/config/load'); var defaults = require('../../lib/config/defaults'); var cli = require('../../lib/cli/'); var path = require('path'); var testUtils = require('../utils'); var utils = require('../../lib/utils'); var rules = require('../../lib/rules'); var exec = require('../../lib/config/exec'); var nodemon = require('../../lib/nodemon'); var command = require('../../lib/config/command'); var assert = require('assert'); function asCLI(cmd) { return ('node nodemon ' + (cmd || '')).trim(); } function commandToString(command) { return utils.stringify(command.executable, command.args); } describe('config load', function () { var pwd = process.cwd(), oldhome = utils.home; afterEach(function () { process.chdir(pwd); utils.home = oldhome; }); after(function (done) { // clean up just in case. nodemon .once('exit', function () { nodemon.reset(done); }) .emit('quit'); }); function removeRegExp(options) { delete options.watch.re; delete options.ignore.re; } beforeEach(function () { // move to the fixtures directory to allow for config loading process.chdir(path.resolve(pwd, 'test/fixtures')); utils.home = path.resolve( pwd, ['test', 'fixtures', 'global'].join(path.sep) ); rules.reset(); nodemon.config.reset(); }); it.skip('should remove ignore defaults if user provides their own', function (done) { nodemon({ script: testUtils.appjs, verbose: true, }) .on('log', function (event) { // console.log(event.colour); }) .on('start', function () { assert.ok( nodemon.config.options.ignore.indexOf('one') !== -1, 'Contains "one" path' ); assert.ok( nodemon.config.options.ignore.indexOf('three') !== -1, 'Contains "three" path' ); // note: we use the escaped format: \\.git assert.ok( nodemon.config.options.ignore.indexOf('\\.git') === -1, 'nodemon is not ignoring (default) .git' ); nodemon.on('exit', function () { nodemon.reset(done); }); setTimeout(function () { nodemon.emit('quit'); }, 1000); }); }); it('should read global config', function (done) { var config = {}, settings = { quiet: true }, options = {}; load(settings, options, config, function (config) { assert(config.verbose, 'we are verbose'); // ensure global mapping works too var options = exec({ script: 'template.pug' }, config.execMap); assert( options.exec === 'bin/pug template.pug --out /tmp', 'exec used, should be "bin/pug": ' + options.exec ); done(); }); }); it('should read package.json config', function (done) { var dir = path.resolve(pwd, 'test/fixtures/packages/package-json-settings'); process.chdir(dir); var config = {}, settings = { quiet: true }, options = {}; load(settings, options, config, function (config) { assert.deepEqual(config.exec, 'foo', 'exec is "foo": ' + config.exec); done(); }); }); it('should give local files preference', function (done) { var config = {}, settings = { quiet: true }, options = {}; load(settings, options, config, function (config) { removeRegExp(config); assert.ok( config.ignore.indexOf('one') !== -1, 'ignore contains "one": ' + config.ignore ); assert.ok( config.ignore.indexOf('three') !== -1, 'ignore contains "three": ' + config.ignore ); assert.deepEqual( config.watch, ['four'], 'watch is "four": ' + config.watch ); done(); }); }); it('should give local files preference over package.json config', function (done) { var dir = path.resolve( pwd, 'test/fixtures/packages/nodemon-settings-and-package-json-settings' ); process.chdir(dir); var config = {}, settings = { quiet: true }, options = {}; load(settings, options, config, function (config) { assert.deepEqual(config.exec, 'foo', 'exec is "foo": ' + config.exec); done(); }); }); it('should give package.json config preference', function (done) { var dir = path.resolve(pwd, 'test/fixtures/packages/package-json-settings'); process.chdir(dir); var config = {}, settings = { quiet: true }, options = {}; load(settings, options, config, function (config) { removeRegExp(config); assert.deepEqual(config.exec, 'foo', 'exec is "foo": ' + config.exec); assert.ok( config.ignore.indexOf('one') !== -1, 'ignore contains "one": ' + config.ignore ); assert.ok( config.ignore.indexOf('three') !== -1, 'ignore contains "three": ' + config.ignore ); assert.deepEqual( config.watch, ['four'], 'watch is "four": ' + config.watch ); done(); }); }); it('should give user specified settings preference', function (done) { var config = {}, settings = { ignore: ['one'], watch: ['one'], quiet: true }, options = {}; load(settings, options, config, function (config) { removeRegExp(config); assert( config.ignore.indexOf('one') !== -1, '"one" is ignored: ' + config.ignore ); assert.deepEqual( config.watch, ['one'], 'watch is "one": ' + config.watch ); done(); }); }); it('should give user specified settings preference over package.json config', function (done) { var dir = path.resolve(pwd, 'test/fixtures/packages/package-json-settings'); process.chdir(dir); var config = {}, settings = { exec: 'foo-user', quiet: true }, options = {}; load(settings, options, config, function (config) { assert.deepEqual( config.exec, 'foo-user', 'exec is "foo-user": ' + config.exec ); done(); }); }); it('should give user specified exec preference over package.scripts.start', function (done) { var dir = path.resolve(pwd, 'test/fixtures/packages/start-and-settings'); process.chdir(dir); var config = {}, settings = { script: './index.js' }, options = {}; load(settings, options, config, function (config) { assert.deepEqual(config.exec, 'foo', 'exec is "foo": ' + config.exec); done(); }); }); it('should give package.json specified exec config over package.scripts.start', function (done) { var dir = path.resolve( pwd, 'test/fixtures/packages/start-and-package-json-settings' ); process.chdir(dir); var config = {}, settings = {}, options = {}; load(settings, options, config, function (config) { assert.deepEqual(config.exec, 'foo', 'exec is "foo": ' + config.exec); done(); }); }); // it('should put the script at the end if found in package.scripts.start', function (done) { // process.chdir(path.resolve(pwd, 'test/fixtures/packages/start')); // allows us to load text/fixtures/package.json // var settings = cli.parse(asCLI('--harmony')); // var config = {}; // var options = {}; // load(settings, options, config, function (config) { // var cmd = commandToString(command(config)); // assert.equal(cmd, 'node --harmony app.js', 'command is ' + cmd); // done(); // }); // }); it('should support "ext" with "execMap"', function (done) { // prevents our test from finding the nodemon.json files process.chdir(path.resolve(pwd, 'test/fixtures/legacy')); utils.home = path.resolve(pwd, 'test/fixtures/legacy'); var settings = { script: './index.js', verbose: true, ignore: ['*/artic/templates/*'], ext: 'js coffee json', watch: ['*.coffee'], execMap: { js: 'node --harmony', coffee: 'node --harmony' }, }; var config = {}; var options = {}; load(settings, options, config, function (config) { var cmd = commandToString(command(config)); assert(cmd === 'node --harmony ./index.js', 'cmd is: ' + cmd); done(); }); }); it('should merge ignore rules', function (done) { load( { ignore: ['*/artic/templates/*', 'views/*'], }, {}, {}, function (config) { assert.equal(config.ignore.length, defaults.ignoreRoot.length + 2); done(); } ); }); it('should allow user to override ignoreRoot', function (done) { load( { ignore: ['*/artic/templates/*', 'views/*'], ignoreRoot: ['.git'], }, {}, {}, function (config) { assert.equal(config.ignore.length, 3); done(); } ); }); it('should merge ignore rules even when strings', function (done) { load( { ignore: 'public', }, {}, {}, function (config) { assert.equal(config.ignore.length, defaults.ignoreRoot.length + 1); done(); } ); }); it('should allow user to override root ignore rules', function (done) { load( { ignore: 'public', ignoreRoot: [], }, {}, {}, function (config) { assert.equal(config.ignore.length, 1); done(); } ); }); it('should allow user to set execArgs', (done) => { const execArgs = ['--inspect']; load( { execArgs, }, {}, {}, (config) => { assert.deepEqual(config.execArgs, execArgs); done(); } ); }); it('should support pkg.main and keep user args on args', (done) => { process.chdir(path.resolve(pwd, 'test/fixtures/packages/main-and-start')); const settings = { scriptPosition: 0, script: null, args: ['first', 'second'], }; const options = { ignore: [], watch: [], monitor: [] }; const config = { run: false, system: { cwd: '/Users/remy/dev/nodemon/issues/1758' }, required: false, dirs: [], timeout: 1000, options: { ignore: [], watch: [], monitor: [] }, lastStarted: 0, loaded: [], }; load(settings, options, config, (res) => { assert.deepEqual(res.execOptions.args, ['first', 'second']); done(); }); }); it('should give package.main preference for script over index.js', function (done) { var dir = path.resolve(pwd, 'test/fixtures/packages/main-and-index'); process.chdir(dir); var config = {}, settings = {}, options = {}; load(settings, options, config, function (config) { assert.deepEqual(config.execOptions.script, 'server.js'); done(); }); }); }); ================================================ FILE: test/docker.sh ================================================ docker build -t nodemon-test-env . docker run --mount type=bind,source=/Users/remy/Sites/nodemon,target=/src/nodemon --name nodemon-test-env --rm -it nodemon-test-env bash # node /nodemon-src/bin/nodemon.js -V http.js ================================================ FILE: test/events/complete.test.js ================================================ 'use strict'; /* global describe, it, beforeEach, before, after */ var nodemon = require('../../lib/'); var debug = require('debug')('nodemon'); var assert = require('assert'); var path = require('path'); var touch = require('touch'); var utils = require('../utils'); var dir = path.resolve(__dirname, '..', 'fixtures', 'events'); var appjs = path.resolve(dir, 'env.js'); var asCLI = utils.asCLI; var fork = require('child_process').fork; describe('events should follow normal flow on user triggered change', function () { function conf() { utils.port++; return { script: appjs, verbose: true, stdout: false, noReset: true, ext: 'js', env: { PORT: utils.port, NODEMON_ENV: 'nodemon', }, }; } var cwd = process.cwd(); beforeEach(function (done) { debug('beforeEach'); nodemon .once('exit', function () { nodemon.reset(done); }) .emit('quit'); }); before(function () { process.chdir(dir); }); after(function (done) { debug('after'); process.chdir(cwd); nodemon .once('exit', function () { nodemon.reset(function () { setTimeout(done, 1000); }); }) .emit('quit'); }); it('start', function (done) { debug('start'); nodemon(conf()).once('start', function () { assert(true, '"start" event'); done(); }); }); it('config:update', function (done) { nodemon(conf()).on('config:update', function () { assert(true, '"config:update" event'); done(); }); }); it('exit', function (done) { var plan = new utils.Plan(4, function () { nodemon.reset(done); }); var run = 0; nodemon(conf()) .on('exit', function () { plan.assert(true, '"exit" event'); if (run === 1) { setTimeout(function () { plan.assert(true, 'restarting ' + appjs); touch.sync(appjs); }, 1500); } else if (run === 2) { plan.assert(true, 'finished'); } else { plan.assert(false, 'quit too many times: ' + run); } }) .on('start', function () { run++; }); }); it('stdout', function (done) { nodemon(conf()).once('stdout', function (data) { assert(true, '"stdout" event with: ' + data); done(); }); }); it('restart', function (done) { var plan = new utils.Plan(4, function () { nodemon.reset(done); }); nodemon(conf()) .on('restart', function (files) { plan.assert(true, '"restart" event with ' + files); plan.assert( files[0] === appjs, 'restart due to ' + files.join(' ') + ' changing' ); }) .once('exit', function () { plan.assert(true, '"exit" event'); setTimeout(function () { plan.assert(true, 'restarting'); touch.sync(appjs); }, 1500); }); }); }); ================================================ FILE: test/events/scripts.test.js ================================================ 'use strict'; /*global describe:true, it: true, afterEach: true, beforeEach: true, after:true */ var cli = require('../../lib/cli/'), path = require('path'), testUtils = require('../utils'), utils = require('../../lib/utils'), exec = require('../../lib/config/exec'), nodemon = require('../../lib/nodemon'), command = require('../../lib/config/command'), appjs = path.resolve(__dirname, '..', 'fixtures', 'env.js'), assert = require('assert'); function asCLI(cmd) { return ('node nodemon ' + (cmd || '')).trim(); } function parse(cmd) { var parsed = cli.parse(cmd); parsed.execOptions = exec(parsed); return parsed; } function commandToString(command) { return utils.stringify(command.executable, command.args); } describe('nodemon API events', function () { var pwd = process.cwd(), oldhome = utils.home; afterEach(function () { process.chdir(pwd); utils.home = oldhome; }); after(function (done) { // clean up just in case. setTimeout(done, 1000); }); beforeEach(function (done) { // move to the fixtures directory to allow for config loading process.chdir(path.resolve(pwd, 'test/fixtures')); utils.home = path.resolve( pwd, ['test', 'fixtures', 'events'].join(path.sep) ); nodemon.reset(done); }); it('should trigger start event script', function (done) { var plan = new testUtils.Plan(4, done); nodemon({ script: appjs, verbose: true, stdout: false, env: { NODEMON_ENV: 'nodemon' }, }) .on('start', function () { plan.assert(true, 'started'); }) .on('exit', function () { plan.assert(true, 'exit'); }) .on('stdout', function (data) { data = data.toString().trim(); if (data === 'OK') { plan.assert(true, 'OK found'); } else if (data === 'STOPPED') { plan.assert(true, 'STOPPED found'); } else if (data === 'nodemon') { // expected output } else { plan.assert(false, data + ' found'); } }); }); }); ================================================ FILE: test/fixtures/.dotfile ================================================ ================================================ FILE: test/fixtures/.dotfolder/.nested_dotfile.js ================================================ ================================================ FILE: test/fixtures/.dotfolder/second.js ================================================ ================================================ FILE: test/fixtures/.dotfolder/some_file.js ================================================ ================================================ FILE: test/fixtures/1246/app/index.js ================================================ require('http').createServer((req, res) => res.end('ok')).listen(8000); ================================================ FILE: test/fixtures/1246/watching/index.js ================================================ require('http').createServer((req, res) => res.end('ok')).listen(8000); ================================================ FILE: test/fixtures/app with spaces.js ================================================ #!/usr/bin/env node console.log(process.argv[2] || 'OK'); require('http').createServer(function (req, res) { console.log('Request in'); res.end('ok'); }).listen(process.env.PORT || 8000); ================================================ FILE: test/fixtures/app.coffee ================================================ http = require 'http' server = http.createServer (req, res) -> res.end 'hi\n' server.listen process.env.PORT || 8000 # console.log "Listening on port 8000" ================================================ FILE: test/fixtures/app.js ================================================ // process.title = 'node (fixtures/app)'; // console.log('starting up @ ' + (process.env.PORT || 8000)); require('http').createServer(function (req, res) { console.log('Request in'); res.end('ok'); }).listen(process.env.PORT || 8000); process.on('SIGINT', function() { process.exit(130) }) ================================================ FILE: test/fixtures/comments ================================================ # this is a comment # this is another comment # *.js ================================================ FILE: test/fixtures/configs/public-star.json ================================================ { "ignore": "public/*", "ext": "json,js,html", "verbose": true } ================================================ FILE: test/fixtures/configs/top-level.json ================================================ { "verbose": "true", "watch": [ "*.js", "app/", "helpers/", "routes/", "view/", "views/" ], "ext": "js json html", "exec": "node --harmony-generators" } ================================================ FILE: test/fixtures/configs/watch-options.json ================================================ { "ext": "json,js,html", "watchOptions": { "awaitWriteFinish": true } } ================================================ FILE: test/fixtures/configs/watch-relative-filter.json ================================================ { "ext": "json,js,html", "watch": ["../jsbin/views", "../jsbin/lib", "../jsbin/*.json", "config.dev.json"] } ================================================ FILE: test/fixtures/configs/watch-relative.json ================================================ { "watch": [ "../../../lib" ], "ext": "py" } ================================================ FILE: test/fixtures/default ================================================ # this is my ignore file with a nice comment at the top /vendor/* # ignore all external submodules /public/* # static files ./README.md # a specific file *.css # ignore any CSS files too :(\d)*\.js # monitor javascript files with only digits in their name ================================================ FILE: test/fixtures/default.json ================================================ { "watch": [ "./", "lib", "src", "plugins" ], "ext": "js css html", "exec": "node", "delay": 2, "ignore": [ "/vendor/*", "/public/*", "./README.md", "*.css", "/vendor/*", ":(\\d)*\\.js" ] } ================================================ FILE: test/fixtures/env.js ================================================ console.log(process.env.NODEMON_ENV); ================================================ FILE: test/fixtures/events/env.js ================================================ console.log(process.env.USER); ================================================ FILE: test/fixtures/events/nodemon.json ================================================ { "verbose": "true", "ext": "js", "events": { "start": "echo 'OK'", "crash": "echo 'CRASHED'", "exit": "echo 'STOPPED'", "quit": "echo 'QUIT'" } } ================================================ FILE: test/fixtures/global/nodemon.json ================================================ { "verbose": true, "ignore": ["one", "two"], "execMap": { "pug": "bin/pug {{filename}} --out /tmp" } } ================================================ FILE: test/fixtures/hello.ls ================================================ http = require 'http' server = http.createServer (req, res) -> res.end 'hi\n' server.listen process.env.PORT console.log "Listening..." ================================================ FILE: test/fixtures/hello.py ================================================ print("Hello, World!") ================================================ FILE: test/fixtures/help.txt ================================================ This file should not be read. ================================================ FILE: test/fixtures/legacy/.nodemonignore ================================================ # this is my ignore file with a nice comment at the top /vendor/* # ignore all external submodules /public/* # static files ./README.md # a specific file *.css # ignore any CSS files too :(\d)*\.js # ignore javascript files with only digits in their name app.json # any app.json file ================================================ FILE: test/fixtures/log.coffee ================================================ console.log "CoffeeScript!" ================================================ FILE: test/fixtures/nodemon.json ================================================ { "ignore": ["one", "three"], "watch": ["four"], "env": { "USER": "remysharp" }, "execMap": { "js": "node --harmony" } } ================================================ FILE: test/fixtures/package.json ================================================ { "main": "app.js" } ================================================ FILE: test/fixtures/packages/browserify/package.json ================================================ { "scripts": { "start": "browserify -t hbsfy app.js -o bundle.js" } } ================================================ FILE: test/fixtures/packages/express4/package.json ================================================ { "name": "express4-gen", "version": "0.0.1", "private": true, "scripts": { "start": "NODE_ENV=development node ./bin/www" }, "dependencies": { "express": "~4.2.0", "static-favicon": "~1.0.0", "morgan": "~1.0.0", "cookie-parser": "~1.0.1", "body-parser": "~1.0.0", "debug": "~0.7.4", "pug": "~2.0.4", "pug-cli": "~1.0.0" } } ================================================ FILE: test/fixtures/packages/main-and-index/index.js ================================================ ================================================ FILE: test/fixtures/packages/main-and-index/package.json ================================================ { "main": "server.js" } ================================================ FILE: test/fixtures/packages/main-and-index/server.js ================================================ ================================================ FILE: test/fixtures/packages/main-and-start/index.js ================================================ ================================================ FILE: test/fixtures/packages/main-and-start/package.json ================================================ { "main": "./index.js", "scripts": { "start": "node index.js" } } ================================================ FILE: test/fixtures/packages/nodemon-settings-and-package-json-settings/nodemon.json ================================================ { "exec": "foo" } ================================================ FILE: test/fixtures/packages/nodemon-settings-and-package-json-settings/package.json ================================================ { "nodemonConfig": { "exec": "foo-ignored" } } ================================================ FILE: test/fixtures/packages/package-json-settings/package.json ================================================ { "nodemonConfig": { "exec": "foo", "ignore": ["one", "three"], "watch": ["four"] } } ================================================ FILE: test/fixtures/packages/start/package.json ================================================ { "scripts": { "start": "node app.js" } } ================================================ FILE: test/fixtures/packages/start-and-package-json-settings/package.json ================================================ { "scripts": { "start": "node app.js" }, "nodemonConfig": { "exec": "foo" } } ================================================ FILE: test/fixtures/packages/start-and-settings/nodemon.json ================================================ { "exec": "foo" } ================================================ FILE: test/fixtures/packages/start-and-settings/package.json ================================================ { "scripts": { "start": "node app.js" } } ================================================ FILE: test/fixtures/packages/start-ignored/package.json ================================================ { "scripts": { "start": "foo" } } ================================================ FILE: test/fixtures/regexp ================================================ :(\d)*\.js # monitor javascript files with only digits in their name ================================================ FILE: test/fixtures/repl.js ================================================ var repl = require('repl'); // Start Express or something, when it's up, startup the REPL var rpl = repl.start('REPL> '); rpl.commands['.hello'] = { help: 'Hello world command.', action: function() { console.log('Hello world.'); } }; ================================================ FILE: test/fixtures/sigint.js ================================================ process.on('SIGINT', function() { if (process.argv.length === 3 && process.argv[2] === '--dont-exit') return; process.exit(); }); // timer, to keep process running setInterval(function() { // console.log('working'); }, 1000); ================================================ FILE: test/fixtures/simple ================================================ # this is my ignore file with a nice comment at the top /vendor/* # ignore all external submodules /public/* # comment ./README.md # a specific file *.css # ignore any CSS files too ================================================ FILE: test/fixtures/simple.json ================================================ { "watch": [ "*.js" ], "ignore": [ "/public/*" ] } ================================================ FILE: test/fixtures/super-legacy/nodemon-ignore ================================================ # this is my ignore file with a nice comment at the top /vendor/* # ignore all external submodules /public/* # static files ./README.md # a specific file *.css # ignore any CSS files too :(\d)*\.js # monitor javascript files with only digits in their name ================================================ FILE: test/fixtures/watch-count/index.js ================================================ true; ================================================ FILE: test/fixtures/watch-count/lib/1.js ================================================ ================================================ FILE: test/fixtures/watch-count/lib/2.js ================================================ ================================================ FILE: test/fixtures/watch-count/lib/3.js ================================================ ================================================ FILE: test/fixtures/watch-count/lib/4.js ================================================ ================================================ FILE: test/fixtures/watch-count/lib/5.js ================================================ ================================================ FILE: test/fork/change-detect.test.js ================================================ 'use strict'; /*global describe:true, it: true */ var utils = require('../utils'), colour = require('../../lib/utils/colour'), assert = require('assert'), touch = require('touch'), appjs = utils.appjs, appcoffee = utils.appcoffee, match = utils.match, cleanup = utils.cleanup, run = utils.run; describe('nodemon fork simply running', function () { it('should start', function (done) { var p = run(appjs, { output: function (data) { if (match(data, appjs)) { assert(true, 'nodemon started'); cleanup(p, done); } }, error: function (data) { assert(false, 'nodemon failed with ' + data); cleanup(p, done); } }); }); }); describe('nodemon fork monitor', function () { it('should restart on .js file changes with no arguments', function (done) { var startWatch = false; var p = run(appjs, { output: function (data) { if (match(data, 'files triggering change check: test/fixtures/app.js')) { startWatch = true; } if (startWatch && match(data, 'changes after filters')) { var changes = colour.strip(data.trim()); var restartedOn = null; changes.replace(/changes after filters \(before\/after\): \d+\/(\d+)/, (_, m) => { restartedOn = m; }); // .split('changes after filters').pop().split('/'); // var restartedOn = changes.pop().trim(); assert.equal(restartedOn, '1', 'nodemon restarted on 1 file: ' + restartedOn + ' / ' + data.toString()); } }, error: function (data) { utils.cleanup(p, done, new Error(data)); } }); p.on('message', function (event) { if (event.type === 'restart') { utils.cleanup(p, done); } else if (event.type === 'start') { setTimeout(function () { touch.sync(appjs); }, 1000); } }); }); it('should NOT restart on non-.js file changes with no arguments', function (done) { setTimeout(function () { var p = run(appjs, { output: function (data) { if (match(data, 'changes after filters')) { data = colour.strip(data.toString().trim()); var changes = data.split('/'); var restartedOn = changes.pop(); assert.equal(restartedOn, '0', 'expects to not have restarted'); utils.cleanup(p, done); } }, error: function (data) { utils.cleanup(p, done, new Error(data)); } }); p.on('message', function (event) { if (event.type === 'start') { setTimeout(function () { // touch a different file, but in the same directory touch.sync(appcoffee); }, 2500); } else if (event.type === 'restart') { utils.cleanup(p, done, new Error('nodemon restarted')); } }); }, 1000); }); }); ================================================ FILE: test/fork/config.test.js ================================================ 'use strict'; /*global describe:true, it: true, afterEach:true, beforeEach:true */ var assert = require('assert'), utils = require('../utils'), path = require('path'), match = utils.match, cleanup = utils.cleanup, run = utils.run; describe('nodemon full config test', function () { var pwd = process.cwd(); beforeEach(function () { // move to the fixtures directory to allow for config loading process.chdir(path.resolve(pwd, 'test/fixtures')); }); afterEach(function () { process.chdir(pwd); }); it('should allow execMap.js to be overridden', function (done) { var p = run({ exec: '../../bin/nodemon.js', args: ['-V'] }, { error: function (data) { p.send('quit'); cleanup(p, done, new Error(data)); }, }); p.on('message', function (event) { if (event.type === 'log') { if (match(event.data.message, 'starting `')) { event.data.message.replace(/`(.*)`/, function (all, m) { assert(m === 'node --harmony app.js', 'Arguments in the correct order: ' + m); // p.send('quit'); cleanup(p, done); }); } } }); }); }); ================================================ FILE: test/fork/run-mac-only.test.js ================================================ const fs = require('fs'); const assert = require('assert'); const utils = require('../utils'); const appJS = utils.appjs; const run = utils.run; const filenames = [ [__dirname + 'some\\\"file', '#!/usr/bin/env node\nconsole.log("OK");'], [__dirname + 'some\ \\file', '#!/bin/sh\necho "OK"'], ]; if (false && !process.env.TRAVIS && process.platform === 'darwin') { describe('nodemon fork (mac only)', () => { before(() => { filenames.map(file => fs.writeFileSync(file[0], file[1], 'utf8')); }); after(() => { filenames.map(file => fs.unlinkSync(file[0])); }); it('should start a fork exec with quotes and escaping', done => { var found = false; var p = run({ exec: 'bin/nodemon.js', // make nodemon verbose so we can check the filters being applied args: ['-q', '--exec', filenames[0][0]] }, { error: function (data) { p.send('quit'); done(new Error(data)); }, output: function (data) { // process.stdout.write(data); if (data.trim() === 'OK') { found = true; } } }); p.on('message', function (event) { if (event.type === 'start') { setTimeout(function () { p.send('quit'); done(); assert(found, '"OK" message was found'); }, 500); } }); }); it('should start a fork exec with spaces and slashes', done => { var found = false; var p = run({ exec: 'bin/nodemon.js', // make nodemon verbose so we can check the filters being applied args: ['-q', '--exec', `"${filenames[1][0]}`] }, { error: function (data) { p.send('quit'); done(new Error(data)); }, output: function (data) { // process.stdout.write(data); if (data.trim() === 'OK') { found = true; } } }); p.on('message', function (event) { if (event.type === 'start') { setTimeout(function () { p.send('quit'); done(); assert(found, '"OK" message was found'); }, 500); } }); }); }); } ================================================ FILE: test/fork/run.test.js ================================================ /*global describe:true, it: true */ var assert = require('assert'), utils = require('../utils'), appjs = utils.appjs, run = utils.run; describe('nodemon fork', function () { it('should not show user-signal', done => { var p = run({ exec: 'bin/nodemon.js', args: [ '-V', '-x', 'echo running && sleep 20' ] }, { error: function (data) { p.send('quit'); if (data.trim().indexOf('signal') !== -1) { return done(new Error('Signal incorrectly shown')); } done(new Error(data)); }, output: function (data) { if (data.trim().indexOf('signal') !== -1) { done(new Error('Signal incorrectly shown')); } } }); let started = false; p.on('message', function (event) { if (event.type === 'start') { if (!started) { p.send('restart'); started = true; } else { p.send('quit'); assert(true, 'nodemon started'); done(); } } }); }); it('should start a fork', function (done) { var p = run(appjs, { error: function (data) { p.send('quit'); done(new Error(data)); } }); p.on('message', function (event) { if (event.type === 'start') { p.send('quit'); assert(true, 'nodemon started'); done(); } }); }); if (!process.env.TRAVIS) { it('should start a fork exec with a space without args', function (done) { var found = false; var p = run({ exec: 'bin/nodemon.js', // make nodemon verbose so we can check the filters being applied args: ['-q', '--exec', 'test/fixtures/app\\ with\\ spaces.js'] }, { error: function (data) { p.send('quit'); done(new Error(data)); }, output: function (data) { // process.stdout.write(data); if (data.trim() === 'OK') { found = true; } } }); p.on('message', function (event) { if (event.type === 'start') { setTimeout(function () { p.send('quit'); done(); assert(found, '"OK" message was found'); }, 500); } }); }); it('should start a fork exec with a space with args', function (done) { var found = false; var p = run({ exec: 'bin/nodemon.js', // make nodemon verbose so we can check the filters being applied args: ['-q', '--exec', '"test/fixtures/app with spaces.js" foo'], }, { error: function (data) { p.send('quit'); done(new Error(data)); }, output: function (data) { if (data.trim() === 'foo') { found = true; } } }); p.on('message', function (event) { if (event.type === 'start') { setTimeout(function () { p.send('quit'); assert(found, '"foo" message found'); done(); }, 500); } }); }); } it('should start a fork exec with a space with args (escaped)', function (done) { var found = false; var p = run({ exec: 'bin/nodemon.js', // make nodemon verbose so we can check the filters being applied args: ['-q', '--exec', 'test/fixtures/app\\ with\\ spaces.js foo'] }, { error: function (data) { p.send('quit'); done(new Error(data)); }, output: function (data) { // process.stdout.write(data); if (data.trim() === 'foo') { found = true; } } }); p.on('message', function (event) { if (event.type === 'start') { setTimeout(function () { p.send('quit'); done(); assert(found, '"OK" message found'); }, 500); } }); }); }); ================================================ FILE: test/fork/watch-restart.test.js ================================================ 'use strict'; /*global describe:true, it: true, after: true */ var assert = require('assert'), fs = require('fs'), utils = require('../utils'), colour = require('../../lib/utils/colour'), appjs = utils.appjs, // appcoffee = utils.appcoffee, run = utils.run, cleanup = utils.cleanup, path = require('path'), touch = require('touch'), crypto = require('crypto'), baseFilename = 'test/fixtures/test' + crypto.randomBytes(16).toString('hex'); describe('nodemon fork child restart', function () { var tmpjs = path.resolve(baseFilename + '.js'), tmpmd = path.resolve(baseFilename + '.md'), tmpcoffee = path.resolve(baseFilename + '.coffee'); afterEach(function () { if (fs.existsSync(tmpjs)) { fs.unlinkSync(tmpjs); } if (fs.existsSync(tmpjs)) { fs.unlinkSync(tmpmd); } if (fs.existsSync(tmpjs)) { fs.unlinkSync(tmpcoffee); } }); /* removed test due to CoffeeScript using depreciate customFds - failing tests */ // it('should cleanly kill entire process tree', function (done) { // fs.writeFileSync(tmpcoffee, 'true'); // var listening = 0; // var p = run('--debug ' + appcoffee, { // error: function (data) { // if (data.indexOf('ebugger listening') === -1) { // p.send('quit'); // cleanup(p, done, new Error(data)); // } // }, // output: function (data) { // if (utils.match(data, 'Listening on port')) { // listening++; // if (listening === 2) { // assert(true, 'nodemon started child successfully twice'); // cleanup(p, done); // } // } // } // }); // var startedOnce = false; // p.on('message', function (event) { // if (startedOnce === false && event.type === 'start') { // startedOnce = true; // setTimeout(function () { // touch.sync(tmpcoffee); // }, 2000); // } else if (event.type === 'restart') { // assert(true, 'nodemon restarted'); // } // }); // }); it('should happen when monitoring a single extension', function (done) { fs.writeFileSync(tmpjs, 'true;'); var p = run('--ext js ' + appjs, { error: function (data) { p.send('quit'); cleanup(p, done, new Error(data)); } }); p.on('message', function (event) { if (event.type === 'start') { setTimeout(function () { touch.sync(tmpjs); }, 1000); } else if (event.type === 'restart') { assert(true, 'nodemon restarted'); cleanup(p, done); } }); }); it('should happen only once if delay option is set', function (done) { var restartCount = 0; fs.writeFile(tmpjs, 'true;', function () { var p = run('--verbose --ext js --delay 2 ' + tmpjs, { error: function (data) { p.send('quit'); cleanup(p, done, new Error(data)); } }); setTimeout(function () { if (restartCount === 1) { assert(true, 'nodemon restarted ' + restartCount + ' times'); cleanup(p, done); } else { cleanup(p, done, new Error('nodemon started ' + restartCount + ' times')); } }, 8000); p.on('message', function (event) { if (event.type === 'log') { // console.log(event.data.colour); } else { // console.log(event.type, Date.now()/1000|0); } // on first start - kick off timeouts to touch the files if (event.type === 'start' && restartCount === 0) { setTimeout(function () { // console.log('touch 1', Date.now()/1000|0); touch.sync(tmpjs); }, 1000); setTimeout(function () { // console.log('touch 2', Date.now()/1000|0); touch.sync(tmpjs); }, 2000); setTimeout(function () { // console.log('touch 3', Date.now()/1000|0); touch.sync(tmpjs); }, 3000); setTimeout(function () { // console.log('touch 4', Date.now()/1000|0); touch.sync(tmpjs); }, 4000); } if (event.type === 'restart') { restartCount++; } }); }); }); it('should happen when monitoring multiple extensions', function (done) { fs.writeFileSync(tmpjs, 'true;'); fs.writeFileSync(tmpmd, '# true'); var monitor = utils.monitorForChange('changes after filters'); setTimeout(function () { var p = run('--ext js,md ' + appjs, { error: function (data) { p.send('quit'); cleanup(p, done, new Error(data)); }, output: function (data) { var msg = colour.strip(data.trim()); if (utils.match(msg, 'changes after filters (before/after)')) { var changes = msg.split(/\n/).shift(); changes = changes.replace(/\s*/gm, '').slice(-5).split('/'); var restartedOn = changes.pop(); assert.equal(restartedOn, '1', 'nodemon restarted on a single file change: ' + restartedOn + ' -- ' + msg); cleanup(p, done); } } }); p.on('message', function (event) { if (event.type === 'start') { setTimeout(function () { touch.sync(tmpmd); }, 1000); } }); }, 2000); }); }); ================================================ FILE: test/help/help.test.js ================================================ /*global describe:true, it: true */ var help = require('../../lib/help'), assert = require('assert'); describe('help', function () { it('should load index by default', function () { var page = help(); assert(page.indexOf('Usage: nodemon') !== -1, 'shows default help page'); }); it('should load specific help topic', function () { var page = help('authors'); assert(page.indexOf('Remy Sharp') !== -1, 'shows specific topic'); }); it('should not expose files', function () { var page = help('../../test/fixtures/help'); assert(page.indexOf('" help can\'t be found') !== -1, 'shows help cannot be found'); }); }); ================================================ FILE: test/lib/events.test.js ================================================ /*global describe:true, it: true */ var nodemon = require('../../lib/'), assert = require('assert'); describe('nodemon events', function () { it('should have (shims) events', function () { assert(nodemon.on); }); it('should allow events to fire', function (done) { nodemon.on('foo', function () { assert(true); done(); }); nodemon.emit('foo'); }); }); ================================================ FILE: test/lib/require-restartable.test.js ================================================ 'use strict'; /*global describe:true, it: true, afterEach: true */ var nodemon = require('../../lib/'), assert = require('assert'), path = require('path'), touch = require('touch'), utils = require('../utils'), appjs = path.resolve(__dirname, '..', 'fixtures', 'app.js'), envjs = path.resolve(__dirname, '..', 'fixtures', 'env.js'); describe('require-able', function () { var pwd = process.cwd(), oldhome = utils.home; afterEach(function () { process.chdir(pwd); utils.home = oldhome; }); beforeEach(function (done) { // move to the fixtures directory to allow for config loading process.chdir(path.resolve(pwd, 'test')); utils.home = path.resolve(pwd, ['test'].join(path.sep)); nodemon.reset(done); }); it('should restart on file change', function (done) { var restarted = false; utils.port++; nodemon({ script: appjs, verbose: true, env: { PORT: utils.port } }).on('start', function () { setTimeout(function () { touch.sync(appjs); }, 1000); }).on('start', function() { if (restarted) { setTimeout(function() { nodemon.emit('quit') }); } }).on('restart', function () { restarted = true; }).on('quit', function () { assert(restarted, 'nodemon restarted and quit properly'); nodemon.reset(done); }).on('log', function (event) { // console.log(event.message); }); }); }); ================================================ FILE: test/lib/require.test.js ================================================ 'use strict'; /*global describe:true, it: true, afterEach: true */ var nodemon = require('../../lib/'), assert = require('assert'), path = require('path'), touch = require('touch'), utils = require('../utils'), appjs = path.resolve(__dirname, '..', 'fixtures', 'app.js'), envjs = path.resolve(__dirname, '..', 'fixtures', 'env.js'); describe('require-able', function () { var pwd = process.cwd(), oldhome = utils.home; afterEach(function () { process.chdir(pwd); utils.home = oldhome; }); beforeEach(function (done) { // move to the fixtures directory to allow for config loading process.chdir(path.resolve(pwd, 'test')); utils.home = path.resolve(pwd, ['test'].join(path.sep)); nodemon.reset(done); }); it('should prioritise options over package.start', function (done) { process.chdir(path.resolve('fixtures/packages/start-ignored')); nodemon({ script: envjs, env: { NODEMON_ENV: 'nodemon' }, stdout: false, }) .on('stdout', function (data) { var out = data.toString().trim(); assert(out === 'nodemon', 'expected output: ' + out); done(); }) .on('error', function (e) { assert(false, 'script did not run: ' + e); done(); }); }); it('should know nodemon has been required', function () { assert(nodemon.config.required, 'nodemon has required property'); }); it('should restart on file change with custom signal', function (done) { var restarted = false; utils.port++; nodemon({ script: appjs, verbose: true, env: { PORT: utils.port }, signal: 'SIGINT', }) .on('start', function () { setTimeout(function () { touch.sync(appjs); }, 1000); }) .on('start', function () { if (restarted) { setTimeout(function () { nodemon.emit('quit'); }); } }) .on('restart', function () { restarted = true; }) .on('quit', function () { assert(restarted, 'nodemon restarted and quit properly'); nodemon.reset(done); }) .on('log', function (event) { // console.log(event.message); }); }); it('should be restartable', function (done) { var restarted = false; nodemon(appjs) .on('start', function () { setTimeout(function () { nodemon.restart(); }, 1000); }) .on('restart', function () { restarted = true; nodemon.emit('quit'); }) .on('quit', function () { assert(restarted); nodemon.reset(done); // unbind events for testing again }); }); }); ================================================ FILE: test/misc/listeners.test.js ================================================ /*global describe, it, beforeEach */ var nodemon = require('../../lib/'); var assert = require('assert'); var path = require('path'); var dir = path.resolve(__dirname, '..', 'fixtures', 'events'); var appjs = path.resolve(dir, 'env.js'); var async = require('async'); describe('listeners clean up', function () { function conf() { return { script: appjs, verbose: true, stdout: false, noReset: true, ext: 'js', env: { PORT: 0, NODEMON_ENV: 'nodemon', }, }; } beforeEach(function (done) { nodemon.reset(done); }); it( 'should be able to re-run in required mode, many times, and not leak' + 'listeners', function (done) { function run(n) { return function (done) { nodemon(conf()); nodemon.on('start', function () { nodemon.on('exit', function () { nodemon.reset(done); }); }); }; } var toRun = '01234567890123456789'.split('').map(run); toRun.push(function () { done(); }); async.series(toRun); } ); }); ================================================ FILE: test/misc/sigint.test.js ================================================ 'use strict'; /*global describe:true, it: true */ var utils = require('../utils'), assert = require('assert'), path = require('path'), appjs = path.relative(process.cwd(), path.resolve(__dirname, '..', 'fixtures', 'sigint.js')), match = utils.match, cleanup = utils.cleanup, run = utils.run, isRunning = utils.isRunning; function runAndKill(done, cmdline, exitcb) { var childPID = null; var p = run(cmdline, { output: function (data) { if (match(data, 'pid: ')) { data.replace(/pid: (\d+)/, function (_, p1) { childPID = p1; }); } }, error: function (data) { assert(false, 'nodemon failed with ' + data); cleanup(p, done); } }); p.on('message', function (event) { if (event.type === 'start') { setTimeout(function () { p.kill('SIGINT'); }, 1000); } }).on('exit', function () { exitcb(childPID); }); } describe('terminal signals', function () { it('should kill child with SIGINT', function (done) { runAndKill(done, appjs, function (childPID) { assert(!isRunning(childPID), 'child is still running at ' + childPID); done(); }); }); it('should terminate nodemon (after ~10 seconds)', function (done) { runAndKill(done, appjs + ' --dont-exit', function (childPID) { // make sure we don't keep abandoned child process.kill(childPID, 'SIGTERM'); done(); }); }); }); ================================================ FILE: test/mocha.opts ================================================ --reporter spec --ui bdd ================================================ FILE: test/monitor/count.test.js ================================================ 'use strict'; /*global describe:true, it: true, after: true */ var nodemon = require('../../lib/'); var utils = require('../utils'); var path = require('path'); var appjs = path.resolve(__dirname, '..', 'fixtures', 'watch-count', 'index.js'); var assert = require('assert'); var watchRe = /watching ([\d,]+) files/; describe('watch count', function () { var pwd = process.cwd(); afterEach(function () { // reset the cwd process.chdir(pwd); }); after(function (done) { // clean up just in case. nodemon.once('exit', function () { nodemon.reset(done); }).emit('quit'); }); it('should respect ignore rules', function (done) { process.chdir('test/fixtures/watch-count'); nodemon({ script: appjs, verbose: true }).on('start', function () { setTimeout(function () { nodemon.once('exit', done).emit('quit'); }, 200); }).on('log', function (data) { var match = null; var count = 0; if (match = data.message.match(watchRe)) { count = match[1].replace(',', '') * 1; assert(count === 6, 'Watching ' + count + ' files, expecting 6.'); } }); }); it('should not watch directory when given a single file', function (done) { process.chdir('test/fixtures/watch-count/'); var watching = 0; nodemon({ script: appjs, verbose: true, watch: appjs }).on('start', function () { setTimeout(function () { assert(watching === 1, `got ${watching} files`); nodemon.once('exit', done).emit('quit'); }, 200); }).on('watching', file => { watching++; }).on('log', function (data) { var match = null; var count = 0; if (match = data.message.match(watchRe)) { count = match[1].replace(',', '') * 1; assert(count === 1, `log showing ${count} files`); } }); }); it('should ignore node_modules from any dir', function (done) { process.chdir('test/fixtures/watch-count/lib'); nodemon({ script: appjs, verbose: true, watch: '..' }).on('start', function () { setTimeout(function () { nodemon.once('exit', done).emit('quit'); }, 200); }).on('log', function (data) { var match = null; var count = 0; if (match = data.message.match(watchRe)) { count = match[1].replace(',', '') * 1; assert(count === 6, 'Watching ' + count + ' files, expecting 6.'); } }); }); }); ================================================ FILE: test/monitor/ignore.test.js ================================================ 'use strict'; /*global describe:true, it: true, after: true */ var assert = require('assert'), path = require('path'), fs = require('fs'), utils = require('../utils'), appjs = utils.appjs, cleanup = utils.cleanup, run = utils.run, files = [], randomFile = function () { return '_nodemon' + (Math.random() * Date.now() | 0); }; function ignore(rule, done, file) { var p = run((rule ? ('-i ' + rule + ' ') : '') + appjs, { output: function (data) { // console.log(data.trim()); }, error: function (data) { p.send('quit'); cleanup(p, done, new Error(data)); }, }); p.on('message', function (event) { if (event.type === 'start') { // touch setTimeout(function () { if (!file) { file = path.join(process.cwd(), rule, randomFile()); } files.push(file); fs.writeFile(file, '', function (err) { if (err) { console.log('error on writing file'); cleanup(p, done, new Error(err)); } }); // if this fires, then *nothing* happened, which is good setTimeout(function () { cleanup(p, done); }, 1000); }, 1000); } else if (event.type === 'restart') { assert(false, 'nodemon should not restart'); cleanup(p, done); } }); } describe('nodemon ignore', function () { afterEach(function (done) { files.forEach(function (file) { if (fs.existsSync(file)) { fs.unlinkSync(file); } }); done(); }); it('should be controlled via cli', function (done) { ignore('node_modules', done); }); it('should ignore node_modules by default', function (done) { ignore(null, done, path.join(process.cwd(), 'node_modules', 'mocha', 'node_modules', randomFile())); }); }); ================================================ FILE: test/monitor/match.test.js ================================================ 'use strict'; /*global describe:true, it: true */ var assert = require('assert'), match = require('../../lib/monitor/match'), config = require('../../lib/config'), path = require('path'), fs = require('fs'), nodemonUtils = require('../../lib/utils'), defaults = require('../../lib/config/defaults'), utils = require('../utils'), watch = require('../../lib/monitor/watch'), merge = nodemonUtils.merge; describe('match', function () { var monitor = [ '!.git', '!node_modules/*', '!public/*', '!npm-debug.log', '!node_modules/*', 'views/server/*', '!*.coffee', ]; it('should resolve ./ in positive match', () => { const cwd = process.cwd(); const res = match( [cwd + '/app.nodemon'], ['./*.nodemon', '!**/dir/*.nodemon'], 'js,mjs,json,nodemon' ); assert.equal(res.result.length, 1, JSON.stringify(res)); }); it('should resolve ./ in positive match (miss test)', () => { const cwd = process.cwd(); const res = match( [cwd + '/dir/app.nodemon'], ['./*.nodemon', '!**/dir/*.nodemon'], 'js,mjs,json,nodemon' ); assert.equal(res.result.length, 0, JSON.stringify(res)); assert.equal(res.ignored, 1, JSON.stringify(res)); }); it('should resolve ./ in negative match (hit test)', () => { const cwd = process.cwd(); const res = match( [cwd + '/app.nodemon'], ['!./*.nodemon', '**/dir/*.nodemon'], 'js,mjs,json,nodemon' ); assert.equal(res.result.length, 0, JSON.stringify(res)); assert.equal(res.ignored, 1, JSON.stringify(res)); }); it('should handle lots of **s!', () => { const res = match( ['test/fixtures/app.js'], [ '*.*', '!**/.git/**', '!**/.nyc_output/**', '!**/.sass-cache/**', '!**/bower_components/**', '!**/coverage/**', ], 'js,mjs,json' ); assert.equal(res.result.length, 1, JSON.stringify(res)); }); it('should match zero files', function () { var files = [ 'views/server/remy.coffee', 'random.coffee', '/User/remy/app/server/foo.coffee', ]; var results = match(files, monitor); // ignoring extension support assert(results.result.length === 0, 'matched ' + results.result.length); }); it('should match one file', function () { var files = [ 'views/server/remy.js', 'random.coffee', '/User/remy/app/server/foo.coffee', ]; var results = match(files, monitor); assert(results.result.length === 1, 'matched ' + results.result.length); }); it('should match two files', function () { var files = [ 'views/server/test.js', 'views/server/test2.js', 'views/server/test.coffee', ]; var results = match(files, monitor); assert(results.result.length === 2, 'matched ' + results.result.length); }); it('should match one file', function () { var files = [ 'views/server/remy.js', 'views/server/ignore.js', 'random.coffee', '/User/remy/app/server/foo.coffee', ]; monitor.push('!views/server/ignore.js'); var results = match(files, monitor); assert(results.result.length === 1, 'matched ' + results.result.length); }); it('should apply *.js to any js file', function () { var files = [utils.appjs]; var result = match(files, ['*.*'], 'js'); assert.deepEqual(result.result, files, 'file returned from match, matches'); assert(result.ignored === 0, 'no files were ignored'); assert(result.watched === files.length, 'a single file was matched'); }); it('should ignore .coffee if watching *.js', function () { var files = [utils.appcoffee]; var result = match(files, ['*.*'], 'js'); assert.deepEqual( result.result, [], 'no results returned: ' + result.result ); }); it('should match .coffee if watching *.js & *.coffee', function (done) { config.load( { ext: 'js coffee', }, function (config) { var files = [utils.appcoffee]; var result = match( files, config.options.monitor, config.options.execOptions.ext ); assert.deepEqual(result.result, files, 'coffee file matched'); assert(result.ignored === 0, '0 files ignored'); done(); } ); }); it('should ignore nodemon default rules', function (done) { config.load({ ext: '*.js' }, function (config) { var files = [utils.appjs, path.join(__dirname, '/.git/foo.js')]; var result = match( files, config.options.monitor, config.options.execOptions.ext ); assert.deepEqual(result.result, files.slice(0, 1), 'first file matched'); assert(result.ignored === 1, '.git file was ignored'); assert(result.watched === 1, 'a single file was matched'); done(); }); }); it('should ignore directories', function (done) { config.load( { ext: 'js', ignore: 'test/fixtures', }, function (config) { var files = [utils.appjs]; var result = match( files, config.options.monitor, config.options.execOptions.ext ); assert.deepEqual(result.result, [], 'should be no files matched'); done(); } ); }); it('should check all directories by default', function (done) { config.load( { ext: 'js', }, function (config) { var files = [utils.appjs]; var result = match( files, config.options.monitor, config.options.execOptions.ext ); assert.deepEqual(result.result, files, 'results should match'); done(); } ); }); it('should be specific about directories', function (done) { config.load( { ext: 'js md pug', watch: ['lib'], }, function (config) { var files = [utils.appjs]; var result = match( files, config.options.monitor, config.options.execOptions.ext ); assert.deepEqual(result.result, [], 'no results'); done(); } ); }); it('should not match coffee when monitoring just js', function (done) { config.load( { script: utils.appjs, }, function (config) { var result = match( [utils.appcoffee], config.options.monitor, config.options.execOptions.ext ); assert.deepEqual(result.result, [], 'no results'); done(); } ); }); it('should ignore case when comparing paths on Windows', function () { if (!nodemonUtils.isWindows) { return; } var results = match(['C:\\TEST\\fixtures'], ['c:\\test\\fixtures']); assert(results.result.length === 1, 'matched ' + results.result.length); }); }); describe('validating files that cause restart', function () { it('should allow for relative paths outside of the cwd', function () { var cwd = process.cwd(); var dir = cwd + '/test/fixtures/configs'; process.chdir(dir); var filename = './watch-relative.json'; var config = JSON.parse(fs.readFileSync(filename)); var settings = merge(config, defaults); var script = path.resolve('../../../lib/__init__.py'); settings.monitor = match.rulesToMonitor(settings.watch, settings.ignore, { dirs: [], system: { useFind: true }, }); var matched = match( [script], settings.monitor, settings.ext.replace(' ', ',') ); process.chdir(cwd); assert( matched.result.length === 1, 'relative file matched: ' + matched.results ); }); it('should allow *.js to match at the top level', function () { var filename = path.join('test', 'fixtures', 'configs', 'top-level.json'); var config = JSON.parse(fs.readFileSync(filename)); var settings = merge(config, defaults); var script = path.resolve('app.js'); settings.monitor = match.rulesToMonitor(settings.watch, settings.ignore, { dirs: [], system: { useFind: true }, }); var matched = match( [script], settings.monitor, settings.ext.replace(' ', ',') ); assert(matched.result.length === 1, 'found match ' + matched.results); }); it('should allow for simple star rule: public/*', function () { var filename = path.join('test', 'fixtures', 'configs', 'public-star.json'); var config = JSON.parse(fs.readFileSync(filename)); var settings = merge(config, defaults); var script = 'public/js/chrome.save.js'; settings.monitor = match.rulesToMonitor(settings.watch, settings.ignore, { dirs: [], system: { useFind: true }, }); var matched = match( [script], settings.monitor, settings.ext.replace(' ', ',') ); assert(matched.result.length === 0, 'public/* ignored: ' + matched.results); }); it('should allow for relative paths with extensions', function () { var cwd = process.cwd(); var dir = cwd + '/test/fixtures/configs'; process.chdir(dir); var filename = './watch-relative-filter.json'; var config = JSON.parse(fs.readFileSync(filename)); var settings = merge(config, defaults); var script = path.resolve('../jsbin/scripts.json'); settings.monitor = match.rulesToMonitor(settings.watch, settings.ignore, { dirs: [], system: { useFind: true }, }); var matched = match( [script], settings.monitor, settings.ext.replace(' ', ',') ); process.chdir(cwd); assert( matched.result.length === 1, 'relative file matched: ' + matched.results ); }); }); describe('match rule parser', function () { it('should support "--watch ."', function () { var config = { watch: '.' }; var settings = merge(config, defaults); var script = 'index.js'; settings.monitor = match.rulesToMonitor(settings.watch, [], { dirs: [], system: { useFind: true }, }); assert( settings.monitor[0] === '*.*', 'path resolved: ' + settings.monitor[0] ); var matched = match([script], settings.monitor, 'js'); assert(matched.result.length === 1, 'no file matched'); }); it('should support "--watch .*"', function () { var config = { watch: '.*' }; var settings = merge(config, defaults); var script = 'index.js'; settings.monitor = match.rulesToMonitor(settings.watch, [], { dirs: [], system: { useFind: true }, }); assert( settings.monitor[0] === '*.*', 'path resolved: ' + settings.monitor[0] ); var matched = match([script], settings.monitor, 'js'); assert(matched.result.length === 1, 'no file matched'); }); it('should support "--watch "', function () { var config = { watch: 'config.json' }; var settings = merge(config, defaults); settings.monitor = match.rulesToMonitor(settings.watch, [], { dirs: [], system: { useFind: true }, }); var matched = match(['/some/path/to/config.json'], settings.monitor, 'js'); assert(matched.result.length === 1, 'no file matched'); }); it('should support "--watch /some/path/*/config.json"', function () { var config = { watch: '/*/config.json' }; var settings = merge(config, defaults); settings.monitor = match.rulesToMonitor(settings.watch, [], { dirs: [], system: { useFind: true }, }); var matched = match(['/some/path/to/config.json'], settings.monitor, 'js'); assert(matched.result.length === 1, 'no file matched'); }); it('should support "--watch *.*"', function () { var config = { watch: '*.*' }; var settings = merge(config, defaults); var script = 'index.js'; settings.monitor = match.rulesToMonitor(settings.watch, [], { dirs: [], system: { useFind: true }, }); assert( settings.monitor[0] === '*.*', 'path resolved: ' + settings.monitor[0] ); var matched = match([script], settings.monitor, 'js'); assert(matched.result.length === 1, 'no file matched'); }); it('should support "--watch .."', function () { // make sure we're in a deep enough directory var cwd = process.cwd(); process.chdir('./test/fixtures/'); var pwd = process.cwd(); var config = { watch: '..' }; var settings = merge(config, defaults); var script = pwd + 'index.js'; settings.monitor = match.rulesToMonitor(settings.watch, [], { dirs: [], system: { useFind: true }, }); process.chdir(cwd); assert( settings.monitor[0] === path.resolve(pwd, '..') + '/**/*', 'path resolved: ' + settings.monitor[0] ); var matched = match([script], settings.monitor, 'js'); assert(matched.result.length === 1, 'no file matched'); }); }); describe('watcher', function () { afterEach(function (done) { config.reset(); setTimeout(() => { watch.resetWatchers(); done(); }, 0); }); it('should not crash if ignoreRoot is an empty array', function (done) { config.load( { watch: ['test/fixtures/app.js'], ignoreRoot: [], }, function (config) { return watch .watch() .then(function () { done(); }) .catch(done); } ); }); it('should not match a dotfile unless explicitly asked to', function (done) { config.load( { watch: ['test/fixtures/*'], }, function (config) { return watch .watch() .then(function (files) { var withDotfile = files.filter(function (file) { return /test\/fixtures\/\.dotfile$/.test(file); }); assert.deepEqual( withDotfile.length, 0, 'should not contain .dotfile' ); done(); }) .catch(done); } ); }); it('should match a dotfile if explicitly asked to', function (done) { config.load( { watch: ['test/fixtures/.dotfile'], }, function (config) { return watch .watch() .then(function (files) { assert.deepEqual( files.filter((f) => f.endsWith('.dotfile')).length, 1, 'should contain .dotfile' ); done(); }) .catch(done); } ); }); it('should match a dotfolder if explicitly asked to', function (done) { config.load( { watch: ['test/fixtures/.dotfolder'], }, function (config) { return watch .watch() .then(function (files) { assert.deepEqual( files.length, 3, 'file lists should contain .dotfolder files' ); done(); }) .catch(done); } ); }); it('should watch relative paths', function () { const monitor = match.rulesToMonitor(['./http.js'], [], { dirs: [], }); var matched = match(['http.js'], monitor, 'js,mjs,json'); assert(matched.result.length === 1, 'found match ' + matched.results); }); it('should ignore relative directories', () => { const monitor = match.rulesToMonitor([], ['node_modules/*', '**/logs/*']); var matched = match(['logs/a'], monitor, 'js,mjs,json'); assert( matched.ignored === 1 && matched.result.length === 0, JSON.stringify(matched) ); }); }); ================================================ FILE: test/monitor/run.test.js ================================================ 'use strict'; /*global describe:true, it: true, after: true, beforeEach */ var nodemon = require('../../lib/'); var assert = require('assert'); var fs = require('fs'); var path = require('path'); var touch = require('touch'); var crypto = require('crypto'); function rnd() { return crypto.randomBytes(16).toString('hex'); } describe('when nodemon runs (2)', function () { var tmp = path.resolve('test/fixtures/test' + rnd() + '.js'); var tmp2 = path.resolve('test/fixtures/test' + rnd() + '-added.js'); afterEach(function () { if (fs.existsSync(tmp)) { fs.unlinkSync(tmp); } if (fs.existsSync(tmp2)) { fs.unlinkSync(tmp2); } }); after(function (done) { // clean up just in case. nodemon.once('exit', function () { nodemon.reset(done); }).emit('quit'); }); beforeEach(function (done) { nodemon.reset(done); }); it('should restart when new files are added', function (done) { fs.writeFileSync(tmp, 'setTimeout(function(){}, 10000)'); nodemon({ script: tmp, }).on('start', function () { setTimeout(function () { fs.writeFileSync(tmp2, 'setTimeout(function(){}, 10000)'); }, 500); }).on('restart', function () { assert(fs.existsSync(tmp2), 'restarted after new file was added'); nodemon.once('exit', function () { nodemon.reset(done); }).emit('quit'); }); }); it('should wait when the script crashes', function (done) { fs.writeFileSync(tmp, 'throw Error("forced crash")'); nodemon({ script: tmp, stdout: false }).on('crash', function () { assert(true, 'detected crashed state'); setTimeout(function () { fs.writeFileSync(tmp, 'var n = 10 + 2;'); }, 1000); }).on('restart', function () { assert(true, 'nodemon restarted'); nodemon.once('exit', function () { nodemon.reset(done); }).emit('quit'); }); }); it('should wait when the script cleanly exits', function (done) { fs.writeFileSync(tmp, 'setTimeout(function () { var n = 10; }, 1000)'); nodemon({ script: tmp }).on('crash', function () { assert(false, 'detected crashed state'); }).on('exit', function () { assert(true, 'nodemon is waiting for a change'); setTimeout(function () { touch.sync(tmp); }, 500); }).on('restart', function () { assert(true, 'nodemon restarted'); nodemon.once('exit', function () { nodemon.reset(done); }).emit('quit'); }); }); it('should expose readable streams when stdout is false', function (done) { var stdoutTestData = 'outputting some data'; var stderrTestData = 'outputting an error'; var script = 'setTimeout(function () { console.log("' + stdoutTestData + '"); }, 5); setTimeout(function () { console.error("' + stderrTestData + '"); }, 10);'; fs.writeFileSync(tmp, script); var stdoutFileName = 'test/fixtures/stdout.txt'; var stderrFileName = 'test/fixtures/stderr.txt'; var stdoutWritable = fs.createWriteStream(stdoutFileName); var stderrWritable = fs.createWriteStream(stderrFileName); nodemon({ script: tmp, stdout: false, }).on('crash', function () { assert(false, 'detected crashed state'); }).on('readable', function () { this.stdout.pipe(stdoutWritable); this.stderr.pipe(stderrWritable); }).on('end', function () { this.stdout.unpipe(stdoutWritable); this.stderr.unpipe(stderrWritable); stdoutWritable.end(); stderrWritable.end(); var stdoutWritableResult = fs.readFileSync(stdoutFileName); var stderrWritableResult = fs.readFileSync(stderrFileName); assert(stdoutWritableResult === stdoutTestData, 'stdout has been piped correctly'); assert(stderrWritableResult === stderrTestData, 'stderr has been piped correctly'); this.emit('quit'); }).once('exit', function () { assert(true, 'nodemon is quitting'); fs.unlinkSync(stdoutFileName); fs.unlinkSync(stderrFileName); nodemon.reset(done); }); }); // Fixed! FIXME this test was previously not working properly // corrected the test case // script should not be run i.e, // file should not be created it('should not run command on startup if runOnChangeOnly is true', function (done) { var script = "var touch = require('touch');\n" + "touch.sync(" + tmp2 + ");\n" fs.writeFileSync(tmp, script); nodemon({ script: tmp, runOnChangeOnly: true, stdout: false, }).on('start', function () { // file exists check assert(!fs.existsSync(tmp2), 'script should not start'); }).once('exit', function () { done(); }); setTimeout(function () { nodemon.emit('quit'); }, 1500); }); it('should kill child on SIGINT', function (done) { fs.writeFileSync(tmp, 'setTimeout(function () { var n = 10; }, 10000)'); nodemon({ script: tmp, verbose: true }).on('start', function () { assert(true, 'nodemon is waiting for a change'); setTimeout(function () { process.once('SIGINT', function () { // do nothing }); process.kill(process.pid, 'SIGINT'); }, 1000); }).on('crash', function () { assert(false, 'detected crashed state'); }).on('exit', function () { assert(true, 'quit correctly'); nodemon.reset(done); setTimeout(function () { process.kill(process.pid, 'SIGINT'); }, 1000); }); }); }); ================================================ FILE: test/monitor/watch-restart.test.js ================================================ 'use strict'; /*global describe, it, after, afterEach */ let debugLogger = {}; const nodemon = require('../../lib/'); var assert = require('assert'); var fs = require('fs'); var utils = require('../utils'); var path = require('path'); var touch = require('touch'); var crypto = require('crypto'); var baseFilename = 'test/fixtures/test' + crypto.randomBytes(16).toString('hex'); var WAIT_BEFORE_START = 3000; describe('nodemon monitor child restart', function () { var tmpjs = path.resolve(baseFilename + '.js'); var tmpmd = path.resolve(baseFilename + '.md'); function write(both) { fs.writeFileSync(tmpjs, 'true;'); if (both) { fs.writeFileSync(tmpmd, '# true'); } } var pwd = process.cwd(); var oldhome = utils.home; afterEach(function () { debugLogger = {}; process.chdir(pwd); utils.home = oldhome; if (fs.existsSync(tmpjs)) { fs.unlinkSync(tmpjs); } if (fs.existsSync(tmpmd)) { fs.unlinkSync(tmpmd); } }); after(function (done) { nodemon .once('exit', function () { nodemon.reset(done); }) .emit('quit'); }); it('should happen when monitoring a single extension', function (done) { write(); setTimeout(function () { nodemon({ script: tmpjs, verbose: true, ext: 'js' }) .on('start', function () { setTimeout(function () { touch.sync(tmpjs); }, 1500); }) .on('restart', function (files) { assert( files[0] === tmpjs, 'nodemon restarted because of change to our file' + files ); nodemon .once('exit', function () { nodemon.reset(done); }) .emit('quit'); }); }, WAIT_BEFORE_START); }); it('should happen when monitoring multiple extensions', function (done) { write(true); setTimeout(function () { nodemon({ script: tmpjs, ext: 'js md', verbose: true, }) .on('start', function () { setTimeout(function () { touch.sync(tmpmd); }, 1500); }) .on('log', function (event) { var msg = event.message; if (utils.match(msg, 'changes after filters')) { var changes = msg .trim() .slice(-5) .split('/'); var restartedOn = changes.pop(); assert( restartedOn === '1', 'nodemon restarted on a single file change' ); nodemon .once('exit', function () { nodemon.reset(done); }) .emit('quit'); } }); }, WAIT_BEFORE_START); }); if (process.platform === 'darwin') { it('should restart when watching directory (mac only)', function (done) { write(true); process.chdir('test/fixtures'); setTimeout(function () { nodemon({ script: tmpjs, verbose: true, ext: 'js', watch: ['*.js', 'global'], }) .on('start', function () { setTimeout(function () { touch.sync(tmpjs); }, 1000); }) .on('restart', function (files) { assert( files.length === 1, 'nodemon restarted when watching directory' ); nodemon .once('exit', function () { nodemon.reset(done); }) .emit('quit'); }); }, WAIT_BEFORE_START); }); } it('should restart when watching directory', function (done) { write(true); // process.chdir(process.cwd() + '/test/fixtures'); setTimeout(function () { nodemon({ script: tmpjs, verbose: true, ext: 'js md', watch: ['test/'], }) .on('start', function () { setTimeout(function () { touch.sync(tmpmd); }, 1000); }) .on('restart', function (files) { assert( files.length === 1, 'nodemon restarted when watching directory' ); nodemon .once('exit', function () { nodemon.reset(done); }) .emit('quit'); }); }, WAIT_BEFORE_START); }); it('should ignore relative node_modules', done => { write(true); process.chdir(process.cwd() + '/test/fixtures/1246/app'); nodemon({ script: 'index.js', watch: ['../'], }) .on('watching', file => { assert( file.indexOf('/node_modules/') === -1, `node_modules found: ${file}` ); }) .on('start', () => { // gentle timeout to wait for the files to finish reading setTimeout(() => { nodemon .once('exit', function () { nodemon.reset(done); }) .emit('quit'); }, 1000); }); }); }); ================================================ FILE: test/monitor/watch.test.js ================================================ 'use-strict'; var assert = require('assert'); var chokidar = require('chokidar'); var process = require('process'); var config = require('../../lib/config'); var watch = require('../../lib/monitor/watch'); describe('watch', function() { it('should pass watchOptions to the watcher', function(done) { process.chdir(process.cwd() + '/test/fixtures/configs'); var passedOptions = {}; var originalWatch = chokidar.watch; chokidar.watch = function(dirs, options) { passedOptions = options; return originalWatch(dirs, options); }; config.load({ configFile: process.cwd() + '/watch-options.json' }, () => { watch.watch(); chokidar.watch = originalWatch; assert(passedOptions.awaitWriteFinish, 'awaitWriteFinish does not have the correct value'); done(); }); }); }) ================================================ FILE: test/rules/index.test.js ================================================ 'use strict'; /*global describe:true, it: true, beforeEach: true */ var fs = require('fs'), nodemon = require('../../lib/nodemon'), rules = require('../../lib/rules'), assert = require('assert'); function loadfixtures(sample) { var path = './test/fixtures/' + sample; return { content: fs.readFileSync(path, 'utf8'), path: path }; } describe('nodemon rules', function () { var fixtures = { comments: loadfixtures('comments'), regexp: loadfixtures('regexp'), default: loadfixtures('default'), simple: loadfixtures('simple'), simplejson: loadfixtures('simple.json'), }; beforeEach(function (done) { nodemon.reset(done); }); it('should be resetable', function (done) { // nodemon.reset(); rules.load('./test/fixtures/simple.json', function () { nodemon.reset(); rules.load('./test/fixtures/comments', function (error, rules) { assert.deepEqual(rules, { watch: [], ignore: [] }, 'rules are empty: ' + JSON.stringify(rules)); done(); }); }); }); it('should read json', function (done) { rules.load('./test/fixtures/simple.json', function (error, rules) { assert(typeof rules === 'object', 'rules file is parsed'); done(); }); }); it('should ignore comments files', function (done) { rules.load(fixtures.comments.path, function (error, rules) { assert.equal(rules.ignore.length, 0, 'zero ignore rules'); done(); }); }); it('should allow comments on lines', function (done) { rules.load(fixtures.simple.path, function (error, rules) { rules.ignore.forEach(function (rule) { assert.equal(rule.indexOf('# comment'), -1, 'no comment found'); }); done(); }); }); it('should ignore regular expressions', function (done) { rules.load(fixtures.regexp.path, function (error, rules) { assert.deepEqual(rules, { 'watch': [], 'ignore': [] }, 'rules are empty'); done(); }); }); }); ================================================ FILE: test/utils/colour.test.js ================================================ /*global describe:true, it: true */ var colour = require('../../lib/utils/colour'), assert = require('assert'); describe('utils colour', function () { it('should colour strings', function () { var red = colour('red', 'foo'); assert(red.indexOf('\x1B') !== -1); }); it('should strip colours strings', function () { var red = colour('red', 'foo'); var plain = colour.strip(red); assert(plain.indexOf('\x1B') === -1); }); }); ================================================ FILE: test/utils/log.test.js ================================================ 'use strict'; /*global describe:true, it: true */ var Logger = require('../../lib/utils/log'); var logger = new Logger(true); var bus = require('../../lib/utils/bus'); var colour = require('../../lib/utils/colour'); var assert = require('assert'); describe('logger', function () { var types = { log: 'black', info: 'yellow', status: 'green', detail: 'yellow', fail: 'red', error: 'red' }; logger.debug = true; Object.keys(types).forEach(function (type) { it('should .' + type, function (done) { bus.once('log', function (event) { assert(event.message === type); assert(event.colour.indexOf(colour[types[type]]) !== -1); done(); }); logger[type](type); }); }); it('should disable colour', function () { var type = 'fail'; bus.once('log', function (event) { assert.equal(event.message, type); assert.ok(event.colour.indexOf(colour[types[type]]) !== -1); }); logger[type](type); logger.useColours = false; bus.once('log', function (event) { assert.equal(event.message, type); assert.ok(event.colour.indexOf(colour[types[type]]) === -1); }); logger[type](type); logger.useColours = true; bus.once('log', function (event) { assert.equal(event.message, type); assert.ok(event.colour.indexOf(colour[types[type]]) !== -1); }); logger[type](type); }); // it('should not log detail if debug is off', function (done) { // logger.debug = false; // function handler() { // assert(false, 'logged a message when we should not have done'); // bus.removeListener('log', handler); // done(); // } // bus.addListener('log', handler); // logger.detail('detail'); // setTimeout(function () { // bus.removeListener('log', handler); // done(); // }, 500); // }); }); ================================================ FILE: test/utils/merge.test.js ================================================ /*global describe:true, it: true */ var merge = require('../../lib/utils/merge'), assert = require('assert'); function getOriginal() { return { verbose: true, script: './lib/app', args: [], execOptions: { verbose: true, script: './lib/app', args: [], exec: 'node', execArgs: [], ext: '' }, restartable: 'rs' }; } describe('utils merge', function () { var original = {}; beforeEach(function () { original = getOriginal(); }); it('should be the same with empty targets', function () { var result = merge(original, {}); assert.deepEqual(original, result); }); it('should merge missing properties', function () { var simple = { ignore: [] }; var result = merge(simple, { watch: [] }); assert.deepEqual({ ignore: [], watch: [] }, result); }); it('should merge complex missing properties', function () { var target = [{ one: 1, two: 2 }, { three: 3, four: 4 }]; var result = merge(original, { watch: target }); original.watch = target; assert.deepEqual(original, result); }); it('should merge deep complex missing properties', function () { var target = { execOptions: { verbose: true, script: './lib/app', args: [], exec: 'node', execArgs: [], ext: '' } }; var result = merge(original, target); original.execOptions = target.execOptions; assert.deepEqual(original, result); }); it('should ignore existing properties', function () { var original = { execOptions: { ext: 'js' } }; var target = { execOptions: { ext: 'notjs' } }; var result = merge(original, target); assert.deepEqual(original, result); original = { ext: 'js' }; target = { ext: 'notjs' }; result = merge(original, target); assert.deepEqual(original, result); }); it('should merge in to "empty" properties', function () { var target = { execOptions: { ext: 'js' } }; var original = { execOptions: { ext: '' } }; var result = merge(original, target); original.execOptions = target.execOptions; assert.deepEqual(original, result); }); it('should merge into empty objects', function () { var original = { foo: 'bar', execOptions: {} }; var target = { execOptions: { ext: 'js' } }; var result = merge(original, target); assert.deepEqual({ foo: 'bar', execOptions: { ext: 'js' } }, result); }); it('should merge into empty arrays', function () { var original = { foo: 'bar', execOptions: [] }; var target = { execOptions: ['js'] }; var result = merge(original, target); assert.deepEqual({ foo: 'bar', execOptions: ['js'] }, result) }); it('should merge into deep empty arrays', function () { // return; var original = { foo: { name: [] } }; var target = { foo: { name: ['remy'] } }; var result = merge(original, target); assert.deepEqual({ foo: { name: ['remy'] } }, result) }); }); ================================================ FILE: test/utils/stringify.test.js ================================================ 'use strict'; /*global describe:true, it: true */ var stringify = require('../../lib/utils').stringify, assert = require('assert'); describe('stringify', function () { it('should combine the executable and arguments', function () { var string = stringify('node', ['./app.js', '--flag']); var expected = 'node ./app.js --flag'; assert(string === expected, "stringified to " + string); }); it('should not include excess whitespace', function () { var string = stringify('node'); var expected = 'node'; assert(string === expected, "stringified to " + string); }); it('should quote arguments with spaces', function () { var string = stringify('node', ['./app.js', '--one --two']); var expected = 'node ./app.js "--one --two"'; assert(string === expected, "stringified to " + string); }); it('should escape quotes', function () { var string = stringify('node', ['./app.js', '--one "--two --three"']); var expected = 'node ./app.js "--one \\"--two --three\\""'; assert(string === expected, "stringified to " + string); }); }); ================================================ FILE: test/utils.js ================================================ 'use strict'; var fork = require('child_process').fork, path = require('path'), appjs = path.resolve(__dirname, 'fixtures', 'app.js'), assert = require('assert'), port = 8000, appcoffee = path.resolve(__dirname, 'fixtures', 'app.coffee'); function asCLI(cmd) { return { exec: 'bin/nodemon.js', // make nodemon verbose so we can check the filters being applied args: ('-V ' + (cmd || '')).trim().split(' ') }; } function match(str, key) { return str.indexOf(key) !== -1; } function monitorForChange(str) { var watch = false; return function (line) { if (match(line, 'files triggering change check: nodemonCheckFsWatch')) { watch = false; } else if (match(line, 'files triggering change check:')) { watch = true; } if (watch) { if (match(line, str)) { return true; } } return false; }; } function run(cmd, callbacks) { var cli = typeof cmd === 'string' ? asCLI(cmd) : cmd; port++; process.env.PORT = port; var proc = fork(cli.exec, cli.args, { env: process.env, cwd: process.cwd(), encoding: 'utf8', silent: true, }); proc.stderr.setEncoding('utf8'); proc.stdout.setEncoding('utf8'); if (callbacks.output) { proc.stdout.on('data', callbacks.output); } if (callbacks.restart) { proc.stdout.on('data', function (data) { if (match(data, 'restarting due to changes')) { callbacks.restart(null, data); } }); } if (callbacks.error) { proc.stderr.on('data', function (error) { error = error.toString().trim(); if (process.env.TRAVIS && error === 'User defined signal 2') { // swallow the SIGUSR2 - it should never hit the stderr, but for some // reason, travis sees it and causes our tests to fail, so we swallow // if this specific error bubbles out } else { callbacks.error(error); } }); } return proc; } function cleanup(p, done, err) { // as above if (process.env.TRAVIS && err && err.message.indexOf('User defined signal 2') === 0) { err = null; } if (p) { p.once('exit', function () { p = null; done(err); }); p.send('quit'); } else { done(err); } } function Plan(count, done) { this.done = done; this.count = count; } Plan.prototype.assert = function() { assert.apply(null, arguments); // console.log(arguments[1]); if (this.count === 0) { assert(false, 'Too many assertions called via "' + arguments[1] + '"'); } else { this.count--; } if (this.count === 0) { this.done(); } }; function getTriggerCount(msg) { var changes = msg.split(/\n/).shift(); changes = changes.replace(/\s*/gm, '').slice(-5).split('/'); return changes.pop(); } function isRunning(pid) { try { process.kill(pid, 0) return true } catch (error) { if (error.code && error.code === 'ESRCH') return false throw error } } module.exports = { getTriggerCount: getTriggerCount, Plan: Plan, asCLI: asCLI, match: match, run: run, cleanup: cleanup, appjs: appjs, appcoffee: appcoffee, monitorForChange: monitorForChange, port: port, isRunning: isRunning }; ================================================ FILE: website/index.html ================================================ nodemon

nodemon reload, automatically.

Nodemon is a utility depended on by over 3 million projects, that will monitor for any changes in your source and automatically restart your server. Perfect for development.

Swap nodemon instead of node to run your code, and now your process will automatically restart when your code changes. To install, get Node.js, then from your terminal run:

npm install -g nodemon

Features

  • Automatic restarting of application.
  • Detects default file extension to monitor.
  • Default support for node but easy to run any executable, such as python, ruby, make, etc.
  • Ignoring specific files or directories.
  • Watch specific directories.
  • Works with server applications or one time run utilities and REPLs.
  • Scriptable through node require statements.
  • Open source and available on github.

Read the full documentation or visit the FAQ

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. Sponsor this project today ❤️
Netpositive Best online casinos not on GamStop in the UK TheCasinoDB Goread.io Best Australian online casinos. Reviewed by Correct Casinos. nongamstopcasinos.net Buy Instagram Likes OnlineCasinosSpelen Beoordelen van nieuwe online casino's 2023 Buy real Instagram followers from Twicsy starting at only $2.97. Twicsy has been voted the best site to buy followers from the likes of US Magazine. SocialWick offers the best Instagram Followers in the market. If you are looking to boost your organic growth, buy Instagram followers from SocialWick Buy Telegram Members We review the entire iGaming industry from A to Z CryptoCasinos.online No deposit casino promo Codes 2024 - The best online Casinos websites. No deposit bonus codes, Free Spins and Promo Codes. Stake, Roobet, Jackpotcity and more. Online casino. Boost your social media presence effortlessly with top-quality Instagram and TikTok followers and likes. Social Media Management and all kinds of followers Betwinner is an online bookmaker offering sports betting, casino games, and more. At Buzzoid, you can buy Instagram followers quickly, safely, and easily with just a few clicks. Rated world's #1 IG service since 2012. Zamsino.com Reviewing and comparing online casinos available to Finnish players. In addition, we publish relevant news and blog posts about the world of iGaming. Buzzvoice is your one-stop shop for all your social media marketing needs. With Buzzvoice, you can buy followers, comments, likes, video views and more! SocialBoosting: Buy Instagram & TikTok Followers, Likes, Views Ігрові автомати онлайн Kasinohai.com Casino Online Chile casino online chile Vanguard Media évalue les casinos en ligne pour joueurs français, testant les sites en France. Nos classements stricts garantissent des casinos fiables et sûrs. Bei Releaf erhalten Sie schnell und diskret Ihr Cannabis Rezept online. Unsere Ärzte prüfen Ihre Angaben und stellen bei Eignung das Rezept aus. Anschließend können Sie legal und sicher medizinisches Cannabis über unsere Partnerapotheken kaufen. Download multithreaded HEIC to JPG converter software for Windows 10/11 We specialize in the online gambling industry, helping players access reliable and verified information about the best online casinos and pokies in Australia. Our team tests casinos and games, collects user reviews from Trustpilot, and organizes them in o Wolf Winner Casino AUCrazyVegas iDealeCasinos BetPokies.co.nz is your New Zealand guide in the world of online gambling. Our site was created by gamblers for gamblers. one x bet - Arabic betting site Online Casino Zonder Registratie We test dozens of casinos every month and select the coolest ones for Australian players. Pokies Reviews Buy TikTok Comments Mi misión es la educación y transparencia en el mundo de los casinos online Spreading knowledge about $ETH Best online sports betting and casino company. bestecasinozondercruks Best online sports betting company in Thailand. Best online sports betting company in Vietnam. We testen elke maand tientallen casino’s en kiezen de beste uit voor Nederlandse spelers. ThePokies Net Aviator Game Online Plinko Game iDEAL Casinos POLi Pay Casinos

Please note that links to the sponsors above are not direct endorsements nor affiliated with any of contributors of the nodemon project.

================================================ FILE: website/oc.jq ================================================ def getImage: . as $_ | { "206432": "https://user-images.githubusercontent.com/13700/127474039-8ba5ac8c-2095-4984-9309-54ff15e95340.png", "215800": "https://user-images.githubusercontent.com/13700/151881982-04677f3d-e2e1-44ee-a168-258b242b1ef4.svg", "327241": "https://user-images.githubusercontent.com/13700/187039696-e2d8cd59-8b4e-438f-a052-69095212427d.png", "348965": "https://user-images.githubusercontent.com/13700/199964872-a86bc00b-4273-4251-ae6a-254b0b643d47.jpg", "368126": "https://user-images.githubusercontent.com/13700/207157616-8b6d3dd2-e7de-4bbf-86b2-d6ad9fb714fb.png", "471843": "https://github-production-user-asset-6210df.s3.amazonaws.com/13700/277616726-33b554c8-24e0-4570-b8ed-293fb2ab2448.jpg", "501897": "https://github-production-user-asset-6210df.s3.amazonaws.com/13700/286696172-747dca05-a1e8-4d93-a9e9-95054d1566df.png", # "525119": "https://github.com/remy/nodemon/assets/13700/820935c0-7844-4ba9-9563-b1c559895c38", # "": "https://github.com/user-attachments/assets/e25d9ccd-1203-449b-9404-fe7336ac180a" } | (.["\($_.MemberId)"] // $_.image) ; def getUrl: . as $_ | { "327241": "https://www.noneedtostudy.com/take-my-online-class/", "348965": "https://www.testarna.se/casino/utan-svensk-licens/", "368126": "https://casinofrog.com/ca/online-casino/new/", "468969": "https://bestnongamstopcasinos.net/", "501897": "https://buycheapestfollowers.com/buy-telegram-channel-members", # "525119": "https://finance.yahoo.com/news/30-best-casinos-not-gamstop-091943696.html", "532050": "https://skweezer.net/buy-instagram-followers", "596376": "https://buzzoid.com/buy-instagram-followers/", "725832": "https://www.favbet.ro/ro/casino/pacanele/", "751387": "https://www.softorbits.net/convert-heic-to-jpeg/" } | (.["\($_.MemberId)"] // $_.website) ; def getAlt: . as $_ | { "319480": { description: "casino online stranieri" }, "321538": { description: "bonus benvenuto scommesse" }, "327241": { description: "Do My Online Class - NoNeedToStudy.com" }, "348965": { description: "Testarna" }, "368126": { description: "New casinos 2023" }, "471843": { description: "Aviators" }, "501897": { description: "Buy Telegram Members" }, # "525119": { description: "30 Best Casinos Not on Gamstop in 2024" }, "532050": { description: "buy instagram followers on skweezer.net today"}, "751387": { description: "Download multithreaded HEIC to JPG converter software for Windows 10/11" }, } | (.["\($_.MemberId)"] // $_) | if .description then .description elif .name then .name else "" end | @html ; def tohtml: "\(getAlt)" ; def tomarkdown: "\(getAlt)"; . + [{ # manually added isActive: false, MemberId: "Online Casinos Australia", image: true, tier: 1, createdAt: "2023-09-17 12:00:00", website: "https://online-casinosaustralia.com/", description: "Online Casinos Australia", image: "https://github-production-user-asset-6210df.s3.amazonaws.com/13700/268531585-c2b4e482-0409-4664-9aa2-95a62b0d606d.png" },{ isActive: false, tier: 1, MemberId: "slotozilla", image: true, createdAt: "2023-11-29 12:00:00", website: "https://www.slotozilla.com/au/free-spins", description: "free spins no deposit", image: "https://github-production-user-asset-6210df.s3.amazonaws.com/13700/286693953-c68112b6-ebe6-49fd-af6a-5c810a54908d.jpg" }, { isActive: true, tier: 1, MemberId: "Youraffe", image: true, createdAt: "2024-12-13 12:00:00", website: "https://zimplerkasinot.net/", image: "https://github.com/user-attachments/assets/cbeddc6e-827a-41eb-b669-a0a4575d068a" }, { isActive: true, tier: 1, MemberId: "Youraffe2", image: true, createdAt: "2025-01-13 12:00:00", website: "https://verovapaatnettikasinot.net/", image: "https://github.com/user-attachments/assets/686bae37-cc29-45e6-b079-ea0bdc101f4e" } ] | def markdown: $markdown; def render: if markdown then tomarkdown else tohtml end; sort_by(.tier, .createdAt) | map(select(getImage) | select($date < .lastTransactionAt) | render) | if markdown then .[] else join("\n") end ================================================ FILE: website/oc.js ================================================ const util = require('node:util'); const exec = util.promisify(require('node:child_process').exec); const { readFile, writeFile, unlink } = require('fs').promises; const web = require('https'); const { resolve } = require('node:path'); const { url } = require('node:inspector'); process.chdir(resolve(__dirname, '..')); const tiers = [26031, 2603]; const files = { html: './website/index.html', markdown: './README.md', jq: './website/oc.jq', }; /** * @param {string} out filename to save to * @returns Promise */ async function curl(out) { const res = []; for (const [i, tier] of tiers.entries()) { const url = `https://opencollective.com/nodemon/members/all.json?TierId=${tier}&limit=100&offset=`; let offset = 0; do { let next = await get(url + offset); console.log(url + offset); res.push(...next.map((_) => ({ ..._, tier: i }))); offset += next.length; if (next.length === 0) break; } while (offset % 100 === 0); } if (res.length === 0) { throw new Error('No results fetched from OpenCollective API'); } console.log(`Writing ${res.length} members to ${out}`); return writeFile(out, JSON.stringify(res)); } /** * @param {string} url * @returns Promise */ function get(url) { return new Promise((resolve, reject) => { web .get(url, (res) => { let contents = ''; res.on('data', (chunk) => (contents += chunk)); res.on('end', () => { try { resolve(JSON.parse(contents)); } catch (err) { reject( new Error(`Failed to parse JSON from ${url}: ${err.message}`) ); } }); res.on('error', (err) => { reject(new Error(`Request failed for ${url}: ${err.message}`)); }); }) .on('error', (err) => { reject(new Error(`Connection failed for ${url}: ${err.message}`)); }); }); } /** * * @param {string} filename * @returns Promise<{ markdown: string, html: string >} */ async function getUpdates(filename) { const date40DaysAgo = new Date(Date.now() - 40 * 24 * 60 * 60 * 1000) .toJSON() .split('T')[0]; const { stdout: markdown } = await exec( `cat ${filename} | jq -r --argjson markdown true --arg date "${date40DaysAgo}" -f ${files.jq}` ); const { stdout: html } = await exec( `cat ${filename} | jq -r --argjson markdown false --arg date "${date40DaysAgo}" -f ${files.jq}` ); return { html: html.trim(), markdown: markdown.trim() }; } /** * @returns Promise<{ markdown: string, html: string >} */ async function getContents() { return { html: await readFile(files.html, 'utf-8'), markdown: await readFile(files.markdown, 'utf-8'), }; } /** * @param {string} insert * @param {string} source * @param {string} filename */ async function combine(insert, source, filename) { // `/s` = . matches new line // console.log(insert); // console.log('-'.repeat(50)); const result = source.replace( /.+/s, `${insert}` ); await writeFile(filename, result); } /** * @param {string} tmp */ async function work(tmp) { await curl(tmp); const insert = await getUpdates(tmp); const source = await getContents(); // Use Promise.all to properly await all async operations await Promise.all( ['html', 'markdown'].map(async (type) => { console.log(`Combining ${type} content`); return combine(insert[type], source[type], files[type]); }) ); } async function main() { let { stdout: tmp } = await exec('mktemp'); tmp = tmp.trim(); console.log(`Created temporary file: ${tmp}`); try { await work(tmp); console.log('Successfully updated the HTML and Markdown files'); // await unlink(tmp); console.log(`Removed temporary file: ${tmp}`); } catch (e) { console.error(`Error during processing: ${e.message}`); console.error(e.stack); try { // Attempt to clean up temp file // await unlink(tmp); console.log(`Removed temporary file: ${tmp}`); } catch (unlinkErr) { console.error( `Failed to remove temporary file ${tmp}: ${unlinkErr.message}` ); } process.exit(1); } } main().catch((e) => { console.error(`Unhandled error in main: ${e.message}`); console.error(e.stack); process.exit(1); }); ================================================ FILE: website/style.css ================================================ body, html { margin: 0; min-height: 100%; background: #2b2922; color: #eee; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif; font-size: 20px; font-weight: 200; line-height: 1.5; } html { margin-bottom: 20px; } header, footer { background: #76d04b; padding: 10px; position: relative; /* background: white; */ } footer p { padding-top: 20px; padding-bottom: 20px; } svg { width: 200px; height: 200px; margin: 0 auto; padding: 80px 0 0; border: 1px solid #77d04b; display: block; fill: #4f4d3f; } header, footer a, footer p { color: #4f4d3f; } h1 { padding: 40px 0 0 0; font-weight: 300; } h2 { font-weight: 100; } header strong { font-weight: 500; font-size: 110%; } header h1, header h2 { text-align: center; } body > p, h2, ul { margin: 20px 48px; } main > ul { padding-left: 60px; } code { font-weight: 100; font-size: 22px; font-family: 'courier new'; } pre code { font-family: courier; } pre { white-space: pre-wrap; background: #000; border-radius: 4px; padding: 20px 48px; } a { color: #fff; font-weight: 400; } footer { margin-top: 40px; padding: 10px 28px; } footer p { font-size: 80%; margin-top: 4px; margin-bottom: 4px; } footer a { padding: 10px; } main > *, footer > * { max-width: 800px; margin: 20px auto; padding-left: 20px; padding-right: 20px; } @media screen and (max-width: 840px) { pre { border-radius: 0; } body > p, h2, ul { margin: 20px 10px; } main > ul { margin-left: 0px; padding-left: 48px; } footer { padding: 10px 12px; } pre, pre code { margin: 10px 0; } } #sponsors { border-top: 1px solid #fff; margin-top: 80px; padding-top: 20px; } #sponsors div { display: flex; flex-direction: row; } #sponsors img { filter: drop-shadow(0px 0px 8px rgba(255, 255, 255, 0.5)); margin-right: 20px; border-radius: 2px; height: 120px; object-fit: contain; }