Last active
December 1, 2022 04:53
-
-
Save shinokada/3d2f7fd48b9ea9a75349fd4bad3c617d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app.js | |
// run this with DEBUG=app node app.js DEBUG=+ node app.js | |
// Add these to package.json scripts: | |
// note using nodemon | |
// "start": "DEBUG=app nodemon app.js", | |
// "debug": "DEBUG=* nodemon app.js", | |
const express = require('express'); | |
const chalk = require('chalk'); | |
const debug = require('debug')('app'); | |
const morgan = require('morgan'); | |
const path = require('path'); | |
// in package.json you should have: | |
// ------package.json---------- | |
// "nodemonConfig": { | |
// "restartable": "rs", | |
// "delay": 2500, | |
// "env": { | |
// "PORT": 4000 | |
// } | |
// } | |
// ----- end of package.json ----- | |
// type rs to restart the server | |
const PORT = process.env.PORT || 3000; | |
const app = express(); | |
app.use(morgan('tiny')); | |
// if you have a /publc/index.html the next line will serve it | |
app.use(express.static(path.join(__dirname, '/public/'))); | |
app.get('/', (req, res) => { | |
res.send('Hello from my app'); | |
}); | |
app.listen(PORT, () => { | |
debug(`listening on port ${chalk.green(PORT)}`); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment