
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
next-remote-watch
Advanced tools
decorated local server for next.js that enables reloads from data changes
This script replaces next dev
with a version that adds a couple extra features:
/__next_reload
, which will trigger a reload when you hit it with any request. You can also POST
data to this route which will be displayed in the application logs in the terminal.The best way to implement is is to use it as an alias for whatever npm script you used to run next dev
before. For example, you might run it like this in your package.json
:
// ...
"scripts": {
- "start": "next dev"
+ "start": "next-remote-watch"
}
This package utilizes undocumented APIs from next.js that are not subject to semantic versioning. This means that any version bump to next.js, major, minor, or patch, could cause it to break without warning. If you decide to adopt this package, you should lock your next.js version to patch, and be careful when upgrading.
It's also important to note that this package can only be used to replace the development server and should under no circumstances be used in production. There is no reason that its functionality would be necessary in production anyway 😀
This script is very useful when you are loading data in getStaticProps
or getStaticPaths
, and you would like for your application to reload when that data changes.
For example, if you are pulling markdown content from a different repository, you can use this script to watch that repository for changes, then when you change your nextjs files, or any of the content files in the other repository, you get an automatic page reload.
As another example, if you are pulling content from a database of any sort, you could set up a script that triggers a reload when there are changes to your data, this way you can change your database and see an automatic page reload. You could also log any information about data changes to the terminal so it's clear what changed or why the reload was triggered.
It's a small, simple utility but offers a really nice developer experience when working with a nextjs app where the content is split out from the presentation, but you could have people working on either one -- with this script the app produces the same great local dev experience with hot reloads whether the code or the data has changed.
If you'd like to pass in a filepath to be watched, it can be passed directly to the command as such:
// ...
"scripts": {
"start": "next-remote-watch ../some-other-folder/foo"
}
You can use globs, or pass in multiple, space-separated paths to be watched as well.
Option | Shorthand | Example | Description | Default |
---|---|---|---|---|
--root | -r | --root ./src | Path to Nextjs project | process.cwd() |
--event | -e | --event add | Specific event to listen for (add , addDir , change , unlink , unlinkDir | change |
--script | -s | --script ./scripts/sync.js | Node script to be called on event . The file should export a function that accepts two arguments (path , event ). | |
--command | -c | --command 'node ./scripts/sync.js {event} {path}' | Command to be called on event . You can use {event} and {path} in the command, which will be replaced with the respective values. | |
--polling | -p | -p | Whether to use usePolling option in chokidar, typically necessary to successfully watch files over a network; for details on performance impact and use cases see chokidar documentation | false |
If you want changes to be triggered by something other than filesystem events, just send any request to the __next_reload
route and it will hot reload. If you POST
json data to the route in the following format, it will reflect some information into the app logs that display in the terminal.
{
message: "Here's a test message!",
color: "red / green / yellow / blue / magenta / cyan / gray / black / white" // optional
}
...that's it!
FAQs
decorated local server for next.js that enables reloads from data changes
The npm package next-remote-watch receives a total of 4,024 weekly downloads. As such, next-remote-watch popularity was classified as popular.
We found that next-remote-watch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.