$ mkdir server
$ touch server/index.js
$ npm init -y
$ npm install express --save
$ node server/index.js
$ npm install --save-dev babel-cli babel-preset-env
import express from 'express';
let app = express();
app.get('/', (req, res) => { res.send('hello world'); })
app.listen(6060, () => console.log('Running on localhost:6060'));
"scripts": {
"start": "nodemon --watch server --exec babel-node -- server/index.js"
}
$ mkdir server/routes
$ touch server/routes/users.js
import express from 'express'
let router = express.Router()
router.get('/',(req,res)=>{
console.log('get success')
})
router.post('/',(req,res)=>{
console.log('post success')
})
export default router
import express from 'express';
import users from './routes/users'
let app = express();
app.use('/api/users', users)
app.get('/', (req, res) => {
res.send('hello world');
})
app.listen(6060, () => console.log('Running on localhost:6060'));