Skip to content

Commit 869b474

Browse files
author
AJ ONeal
committed
hello: a simple hello world
1 parent 8107d57 commit 869b474

File tree

5 files changed

+1077
-2
lines changed

5 files changed

+1077
-2
lines changed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
1-
# auth3000
2-
Yet another auth library by AJ
1+
# node-express-starter
2+
3+
A template repo for express server apps.
4+
Check the different branches for different templates.
5+
6+
```bash
7+
git clone git@github.com:CHANGE_ME/YOUR_PROJECT.git
8+
pushd YOUR_PROJECT
9+
npm ci
10+
```
11+
12+
Pre-reqs
13+
14+
```bash
15+
# Get webi (and follow instructions)
16+
curl https://webinstall.dev | bash
17+
```
18+
19+
```bash
20+
webi node@lts
21+
webi watchexec
22+
```

app.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"use strict";
2+
3+
require("dotenv").config();
4+
5+
let http = require("http");
6+
let express = require("express");
7+
let app = require("@root/async-router").Router();
8+
9+
if ("DEVELOPMENT" === process.env.ENV) {
10+
// set special options
11+
}
12+
13+
app.get("/hello", function (req, res) {
14+
return { message: "Hello, World!" };
15+
});
16+
17+
// TODO error handler for /api
18+
app.use("/", function (err, req, res, next) {
19+
if (err.code) {
20+
res.statusCode = err.status || 500;
21+
res.json({ status: err.status, code: err.code, message: err.message });
22+
return;
23+
}
24+
25+
console.error("Unexpected Error:");
26+
console.error(err);
27+
res.statusCode = 500;
28+
res.end("Internal Server Error");
29+
});
30+
31+
let server = express().use("/", app);
32+
if (require.main === module) {
33+
let port = process.env.PORT || 3042;
34+
http.createServer(server).listen(port, function () {
35+
/* jshint validthis:true */
36+
console.info("Listening on", this.address());
37+
});
38+
}
39+
40+
module.exports = app;

example.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ENV=DEVELOPMENT
2+
PORT=3000

0 commit comments

Comments
 (0)