https://github.com/codad5/php-inex
Simulating Node.js require in php
https://github.com/codad5/php-inex
node-js php php-library
Last synced: 2 months ago
JSON representation
Simulating Node.js require in php
- Host: GitHub
- URL: https://github.com/codad5/php-inex
- Owner: codad5
- Created: 2022-10-25T18:22:09.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-05T01:48:16.000Z (over 3 years ago)
- Last Synced: 2025-07-12T15:41:23.687Z (12 months ago)
- Topics: node-js, php, php-library
- Language: PHP
- Homepage:
- Size: 39.1 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# PHP IMPORTER
This is a package that simulates node.js import feature.
## Installing it
```
composer require codad5/php-inex
```
## SAMPLE FOR DEFAULT EXPORT
##### Exporting data
- Export.js
```js
export default const greet = () => {
console.log('hello')
}
```
- Export.php
```php
{
console.log('hello')
}
const sum = (a, b) => {
return a + b
}
export {greet, sum}
```
- Export.php
```php
$greet, "sum" => $sum] = Import::this('Export');
$greet(); // hello
echo $sum(2,4) // 6
```
## USING ROUTER LIBRARY
- For php we will use [TrulyAo php-router](https://github.com/aosasona/php-router)
- For Node.js we will use Express.js
##### Exporting routes
- `routes/api.js`
```js
const route = require('express').Router()
route.get('/food', (req, res) => {
res.json({
'name' : "rice"
})
})
export default route
```
- `routes/api.php`
```php
get('/food', function($req, $res){
$res->json([
'name' => "rice"
]);
});
$export = $route;
```
##### Importing routes
- Import.js
```js
const app = require('express')();
const apiRoute = require('routes/api')
app.get('', (req, res) => {
res.send('welcome')
})
app.use('/api', apiRoute)
// serving the application
app.listen(4000)
```
- Import.php
```php
get('/', function($req, $res){
$res->send('welcome');
});
$route->set_route('/api', $apiRoute);
// serving the application
$route->serve();
```
### More
You can also import non php files but you get their file content instead
### Coming soon
- Formatted json import
> Built with 🧡 by [Aniezeofor Chibueze](https://github.com/codad5)