// server.js
var http = require('http');
//create a server object:
http.createServer((req, res) => {
res.write('Hello World!'); //write a response to the client
res.end(); //end the response
}).listen(8080); //the server object listens on port 8080
npm i express --save
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
{
"env": "maui",
"service_name": "service-name"
}
[{
"service_name": "service-name",
"build_version": "2019-01-01-01-01-1234"
}]
npm i nodemon --save-dev
// package.json
"scripts": {
"local:dev": "nodemon index.js"
}
app.js
index.js
src
routers
callback
setTimeout/setInterval
promise
async/await
process.nextTick
eventloop
eventloop
mix callback,promise,async/await,setTimeout
using axios
npm i axios --save
https://floobits.com/yagong/backend
npm i --save-dev jest supertest
npm i --save-dev eslint-plugin-jest
install dependencies
// in package.json add this section
"jest": {
"testEnvironment": "node"
}
// in .eslintrc.js, add plugins:
'plugin:jest/recommended'
configure jest
const app = require('../src/app')
const request = require('supertest')
it('should return hello world', async function() {
const response = await request(app).get('/hello-world')
expect(response.text).toEqual('hello world')
})
Text