Created
December 5, 2019 22:57
-
-
Save senthilmpro/b5950642bc00a855dd796d648fbd8ec8 to your computer and use it in GitHub Desktop.
node.js express server
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
const express = require('express'); | |
const app = new express(); | |
// url requests. GET/POST | |
app.use(express.json()); | |
app.use(express.urlencoded()); | |
app.use(express.static(__dirname + "/public")); | |
// routing. | |
const router = require('./routes/router.js'); | |
app.use('/api/v1', router); | |
const PORT = process.env.PORT || 10101; | |
app.listen(PORT); | |
console.log(`App successfully started at PORT : ${PORT}`); | |
// router.js | |
const router = require('express').Router(); | |
const users = [ | |
{ | |
name : 'admin' | |
} | |
]; | |
router.get('/users', (req,res) => { | |
res.status(200).send(users); | |
}); | |
module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment