Skip to content

Commit 86d59d7

Browse files
npx express-generator --no-view --git -f comma-api-server
1 parent ec504d0 commit 86d59d7

File tree

8 files changed

+168
-74
lines changed

8 files changed

+168
-74
lines changed

.gitignore

Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ logs
44
npm-debug.log*
55
yarn-debug.log*
66
yarn-error.log*
7-
lerna-debug.log*
8-
.pnpm-debug.log*
9-
10-
# Diagnostic reports (https://nodejs.org/api/report.html)
11-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
127

138
# Runtime data
149
pids
@@ -21,12 +16,11 @@ lib-cov
2116

2217
# Coverage directory used by tools like istanbul
2318
coverage
24-
*.lcov
2519

2620
# nyc test coverage
2721
.nyc_output
2822

29-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
3024
.grunt
3125

3226
# Bower dependency directory (https://bower.io/)
@@ -42,27 +36,15 @@ build/Release
4236
node_modules/
4337
jspm_packages/
4438

45-
# Snowpack dependency directory (https://snowpack.dev/)
46-
web_modules/
47-
48-
# TypeScript cache
49-
*.tsbuildinfo
39+
# Typescript v1 declaration files
40+
typings/
5041

5142
# Optional npm cache directory
5243
.npm
5344

5445
# Optional eslint cache
5546
.eslintcache
5647

57-
# Optional stylelint cache
58-
.stylelintcache
59-
60-
# Microbundle cache
61-
.rpt2_cache/
62-
.rts2_cache_cjs/
63-
.rts2_cache_es/
64-
.rts2_cache_umd/
65-
6648
# Optional REPL history
6749
.node_repl_history
6850

@@ -72,59 +54,8 @@ web_modules/
7254
# Yarn Integrity file
7355
.yarn-integrity
7456

75-
# dotenv environment variable files
57+
# dotenv environment variables file
7658
.env
77-
.env.development.local
78-
.env.test.local
79-
.env.production.local
80-
.env.local
8159

82-
# parcel-bundler cache (https://parceljs.org/)
83-
.cache
84-
.parcel-cache
85-
86-
# Next.js build output
60+
# next.js build output
8761
.next
88-
out
89-
90-
# Nuxt.js build / generate output
91-
.nuxt
92-
dist
93-
94-
# Gatsby files
95-
.cache/
96-
# Comment in the public line in if your project uses Gatsby and not Next.js
97-
# https://nextjs.org/blog/next-9-1#public-directory-support
98-
# public
99-
100-
# vuepress build output
101-
.vuepress/dist
102-
103-
# vuepress v2.x temp and cache directory
104-
.temp
105-
.cache
106-
107-
# Docusaurus cache and generated files
108-
.docusaurus
109-
110-
# Serverless directories
111-
.serverless/
112-
113-
# FuseBox cache
114-
.fusebox/
115-
116-
# DynamoDB Local files
117-
.dynamodb/
118-
119-
# TernJS port file
120-
.tern-port
121-
122-
# Stores VSCode versions used for testing VSCode extensions
123-
.vscode-test
124-
125-
# yarn v2
126-
.yarn/cache
127-
.yarn/unplugged
128-
.yarn/build-state.yml
129-
.yarn/install-state.gz
130-
.pnp.*

app.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var express = require('express');
2+
var path = require('path');
3+
var cookieParser = require('cookie-parser');
4+
var logger = require('morgan');
5+
6+
var indexRouter = require('./routes/index');
7+
var usersRouter = require('./routes/users');
8+
9+
var app = express();
10+
11+
app.use(logger('dev'));
12+
app.use(express.json());
13+
app.use(express.urlencoded({ extended: false }));
14+
app.use(cookieParser());
15+
app.use(express.static(path.join(__dirname, 'public')));
16+
17+
app.use('/', indexRouter);
18+
app.use('/users', usersRouter);
19+
20+
module.exports = app;

bin/www

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var app = require('../app');
8+
var debug = require('debug')('comma-api-server:server');
9+
var http = require('http');
10+
11+
/**
12+
* Get port from environment and store in Express.
13+
*/
14+
15+
var port = normalizePort(process.env.PORT || '3000');
16+
app.set('port', port);
17+
18+
/**
19+
* Create HTTP server.
20+
*/
21+
22+
var server = http.createServer(app);
23+
24+
/**
25+
* Listen on provided port, on all network interfaces.
26+
*/
27+
28+
server.listen(port);
29+
server.on('error', onError);
30+
server.on('listening', onListening);
31+
32+
/**
33+
* Normalize a port into a number, string, or false.
34+
*/
35+
36+
function normalizePort(val) {
37+
var port = parseInt(val, 10);
38+
39+
if (isNaN(port)) {
40+
// named pipe
41+
return val;
42+
}
43+
44+
if (port >= 0) {
45+
// port number
46+
return port;
47+
}
48+
49+
return false;
50+
}
51+
52+
/**
53+
* Event listener for HTTP server "error" event.
54+
*/
55+
56+
function onError(error) {
57+
if (error.syscall !== 'listen') {
58+
throw error;
59+
}
60+
61+
var bind = typeof port === 'string'
62+
? 'Pipe ' + port
63+
: 'Port ' + port;
64+
65+
// handle specific listen errors with friendly messages
66+
switch (error.code) {
67+
case 'EACCES':
68+
console.error(bind + ' requires elevated privileges');
69+
process.exit(1);
70+
break;
71+
case 'EADDRINUSE':
72+
console.error(bind + ' is already in use');
73+
process.exit(1);
74+
break;
75+
default:
76+
throw error;
77+
}
78+
}
79+
80+
/**
81+
* Event listener for HTTP server "listening" event.
82+
*/
83+
84+
function onListening() {
85+
var addr = server.address();
86+
var bind = typeof addr === 'string'
87+
? 'pipe ' + addr
88+
: 'port ' + addr.port;
89+
debug('Listening on ' + bind);
90+
}

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "comma-api-server",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"start": "node ./bin/www"
7+
},
8+
"dependencies": {
9+
"cookie-parser": "~1.4.4",
10+
"debug": "~2.6.9",
11+
"express": "~4.16.1",
12+
"morgan": "~1.9.1"
13+
}
14+
}

public/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<html>
2+
3+
<head>
4+
<title>Express</title>
5+
<link rel="stylesheet" href="/stylesheets/style.css">
6+
</head>
7+
8+
<body>
9+
<h1>Express</h1>
10+
<p>Welcome to Express</p>
11+
</body>
12+
13+
</html>

public/stylesheets/style.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
body {
2+
padding: 50px;
3+
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4+
}
5+
6+
a {
7+
color: #00B7FF;
8+
}

routes/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var express = require('express');
2+
var router = express.Router();
3+
4+
/* GET home page. */
5+
router.get('/', function(req, res, next) {
6+
res.render('index', { title: 'Express' });
7+
});
8+
9+
module.exports = router;

routes/users.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var express = require('express');
2+
var router = express.Router();
3+
4+
/* GET users listing. */
5+
router.get('/', function(req, res, next) {
6+
res.send('respond with a resource');
7+
});
8+
9+
module.exports = router;

0 commit comments

Comments
 (0)