Giter Site home page Giter Site logo

boiler-plate's Introduction

  • Ng new
  • Cd into app
  • Npm install —save express body-parser (express organizes an architecture to run on a node server, body parser parses json)
  • Npm install —save axios (for http requests to salesforce’s jsforce api)
  • Npm install —save bootstrap (for easy styling)
  • Create server.js file in root folder, copy and paste this into it ` // Get dependencies const express = require('express'); const path = require('path'); const http = require('http'); const bodyParser = require('body-parser');

// Get our API routes const api = require('./server/routes/api');

const app = express();

// Parsers for POST data app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false }));

// Point static path to dist app.use(express.static(path.join(__dirname, 'dist')));

// Set our api routes app.use('/api', api);

// Catch all other routes and return the index file app.get('*', (req, res) => { res.sendFile(path.join(__dirname, 'dist/index.html')); });

/**

  • Get port from environment and store in Express. */ const port = process.env.PORT || '3000'; app.set('port', port);

/**

  • Create HTTP server. */ const server = http.createServer(app);

/**

  • Listen on provided port, on all network interfaces. */ server.listen(port, () => console.log(API running on localhost:${port})); `
  • Create server folder
  • Create routes folder in server folder
  • Create a api.js file in routes folder ` const express = require('express'); const router = express.Router();

// declare axios for making http requests const axios = require('axios'); const API = 'https://jsonplaceholder.typicode.com';

/* GET api listing. */ router.get('/', (req, res) => { res.send('api works'); });

// Get all posts router.get('/posts', (req, res) => { // Get posts from the mock api axios.get(${API}/posts) .then(posts => { res.status(200).json(posts.data); }) .catch(error => { res.status(500).send(error) }); });

module.exports = router; `

  • Ng build
  • Node server.js

boiler-plate's People

Contributors

angular-cli avatar

Watchers

James Cloos avatar Alan Taylor avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.