Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require('kraken-injection').config() // or like this -> require('kraken-injection/dist/config')
- const express = require('express')
- const http = require('http')
- const app = express()
- const server = http.createServer(app)
- app.get('/', async (req, res) => {
- try {
- const response = await $axios.get('https://jsonplaceholder.typicode.com/users')
- res.status(200).json({ users: response.data })
- } catch (error) {
- res.status(400).json({ error })
- }
- })
- app.get('/:id', async (req, res) => {
- try {
- const response = await $axios.get('https://jsonplaceholder.typicode.com/users')
- const data = $_.find(response.data, (val) => val.id === parseInt(req.params.id) && val)
- res.status(200).json({ user: data })
- } catch (error) {
- res.status(400).json({ error })
- }
- })
- server.listen(process.env.NODE_ENV || 4000, () => console.log(`server running on port ${server.address().port}`))
- /*
- * =======================
- * kraken.config.json
- *========================
- {
- "packages": [
- {
- "name": "$axios",
- "module": "axios"
- },
- {
- "name": "$_",
- "module": "lodash",
- "inject": false // If inject set to false, module cannot be access to
- // global and default value for inject is true
- }
- ]
- }
- */
Add Comment
Please, Sign In to add comment