⌨️
Web Design
  • Index
  • Front End
    • Front End Index
  • HTML/CSS/JS
    • HTML Index
      • Page layout
      • Form
      • Image Optimization
    • CSS Index
      • CSS Selectors
        • Selectors
        • Combinators
        • Attribute Selectors
        • Pseudo classes
      • CSS Cascade and Inheritance
        • Cascade
        • Inheritance
      • Specificity
      • Box Model
      • CSS Clearfix
      • Responsive Meta Tag
      • Flexbox Layout
      • Grid Layout
      • CSS Naming Rules
        • Golden Guidelines for Writing Clean CSS
        • BEM
        • Rules
      • Frameworks & Libraries
    • JS Index
      • JS loading
      • Modules
      • Js Array Common Method 1
      • Js Array Common Method 2
      • Custom attributes on the element
      • Operator
      • Parse a JSON Date in JavaScript
      • Importmap
  • Git
    • Git Index
    • Initialize a Repository
    • Top 20 Git Commands With Examples
  • UML
    • UML Class
  • React
    • Index
      • setState async issue
      • Redux
      • Axios
      • useState update in A Timeout
  • WebGL
    • WebGL Index
  • Back End
    • Back-End Index
      • Knex
      • Bookshelf
        • bookshelf install
        • Bookshelf only returns one row
      • Server side init flow
      • Install Wordpress on Ubuntu 22.04 with a LAMP Stack
  • React Native
    • React Native Index
      • Dynamically changing Image URLs in React Native
  • Expo
    • EAS build config
Powered by GitBook
On this page
  • Step 1
  • Step 2
  • Step 3

Was this helpful?

  1. Back End
  2. Back-End Index

Server side init flow

Step 1

$ 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

index.js

import express from 'express';
let app = express();
app.get('/', (req, res) => { res.send('hello world'); })
app.listen(6060, () => console.log('Running on localhost:6060'));

Step 2

$ touch .babelrc

.babelrc

{
  "presets": ["env"]
}

package.json

"scripts": {
    "start": "nodemon --watch server --exec babel-node -- server/index.js"
  }

Step 3

$ mkdir server/routes
$ touch server/routes/users.js

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

index.js

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'));
PreviousBookshelf only returns one rowNextInstall Wordpress on Ubuntu 22.04 with a LAMP Stack

Last updated 2 years ago

Was this helpful?