Skip to content

Instantly share code, notes, and snippets.

@tedhagos
Created December 6, 2019 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedhagos/fe6129d597be9fe87fb76b3b21738eb4 to your computer and use it in GitHub Desktop.
Save tedhagos/fe6129d597be9fe87fb76b3b21738eb4 to your computer and use it in GitHub Desktop.
Sample node server app for Angular training

Installation

On the same folder where you will download 'app.js', do these things

npm init -y
npm install --save express cors
npm install -g nodemon

To start

nodemon app.js

const express = require('express')
const cors = require('cors')
const app = express()
const port = process.env.PORT || 3000
app.use(cors())
app.get('/test', (req, res) => {
books = [{"id":1,"name":"The C Programming language","author":"Dennis Ritchie","price":10.25,"rating":5,"image":"the-c-programming-language.jpg"},{"id":2,"name":"Pro Angular 6","author":"Adam Freeman","price":29.5,"rating":4.5,"image":"pro-angular6.jpg"},{"id":3,"name":"Angular in Action","author":"Jeremy Wilken","price":37.25,"rating":4,"image":"angular-in-action.jpg"},{"id":4,"name":"Web Development in Node and Express","author":"Ethan Brown","price":19,"rating":4,"image":"webdevelopment-node-express.jpg"},{"id":5,"name":"Angular Up & Running","author":"Shyam Seshadri","price":30,"rating":3.5,"image":"angular-upandrunning.jpg"},{"id":6,"name":"Head First Android","author":"Dawn Griffiths","price":36.95,"rating":4,"image":"headfirst-android.jpg"},{"id":7,"name":"Reactive Programming with RxJava","author":"Tomasz Nurkiewicz","price":30.25,"rating":4.5,"image":"reactive-programming-rxjava.jpg"},{"id":8,"name":"Fullstack JavaScript","author":"Azat Mardan","price":32,"rating":4.5,"image":"fullstack-javascript.jpg"}]
res.json(books)
})
app.listen(port, () => {
console.log(`Server is listening on port: ${port}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment