js-runtime-check
v1.0.2
Published
A npm package to check if this is client or server
Downloads
8
Maintainers
Readme
js-runtime-check
A simple utility function to determine if JavaScript code is currently executing on the client or server side.
Installation
Install via npm:
npm install js-runtime-check
Or via yarn:
yarn add js-runtime-check
Usage
import { isServer } from "js-runtime-check";
// Example usage
if (isServer()) {
console.log("Code is running on the server side.");
} else {
console.log("Code is running on the client side.");
}
API
isServer()
- Returns:
boolean
-true
if code is running on the server side,false
if running on the client side.
Example
import { isServer } from "js-runtime-check";
if (isServer()) {
// Code to execute on the server side
} else {
// Code to execute on the client side
}
Contributing
Contributions are welcome! Please feel free to open issues or submit pull requests on GitHub.
License
This project is licensed under the MIT License - see the LICENSE file for details.