Skip to content

Commit 49a7d50

Browse files
authored
Merge pull request #47 from tvthatsme/master
Add CLI option for custom port number
2 parents a86f630 + e78cc9a commit 49a7d50

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Start the GraphQL server on localhost, port 3000.
4040
json-graphql-server db.js
4141
```
4242

43+
To use a port other than 3000, you can run `json-graphql-server db.js --p <your port here>`
44+
4345
Now you can query your data in graphql. For instance, to issue the following query:
4446

4547
```graphql
@@ -533,7 +535,7 @@ Deploy with Heroku or Next.js.
533535

534536
## Roadmap
535537

536-
* CLI options (port, https, watch, delay, custom schema)
538+
* CLI options (https, watch, delay, custom schema)
537539
* Subscriptions
538540
* Client-side mocking (à la [FakeRest](https://github.com/marmelab/FakeRest))
539541

bin/json-graphql-server.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@ var data = require(path.join(process.cwd(), dataFilePath));
1010
var PORT = process.env.NODE_PORT || 3000;
1111
var app = express();
1212

13+
process.argv.forEach((arg, index) => {
14+
// allow a custom port via CLI
15+
if (arg === '--p' && process.argv.length > index + 1) {
16+
PORT = process.argv[index + 1];
17+
}
18+
});
19+
1320
app.use(cors());
1421
app.use('/', JsonGraphqlServer(data));
1522
app.listen(PORT);
1623
var msg = `GraphQL server running with your data at http://localhost:${PORT}/`;
1724
console.log(msg); // eslint-disable-line no-console
1825

1926
process.on('unhandledRejection', (reason, p) => {
20-
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
27+
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
2128
});

0 commit comments

Comments
 (0)