express js routes how to get the root

Millenial2020

I'm making a website using angular and when the user hits '/' root i want to go the my www/index.html and render that page, and after that angular can take care of the rest. I just want my application to load that index.html before angular takes over.

my question is how do i make my app initialize, and then i can do the rest with angular.

this is my server.js

    // dependencies
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');

// mongodb
mongoose.connect('mongodb://localhost/test');

// express
var app = express();

//route for the root
app.get('/', function(req, res){

  res.render('www/index.html');

});

app.use(bodyParser.urlencoded({ extended: true}));
app.use(bodyParser.json());

// routes
app.use('/api', require('./routes/api'));

// start server
app.listen(3000);


i have a routes/api.js file that basically takes care of the api calls

    // dependencies
var express = require('express');
var router = express.Router();
var app = express();

// models
var User = require('../models/user');

// routes
User.methods(['get', 'put', 'post', 'delete']);
User.register(router, '/users');

// return router
module.exports = router;
Matt Herbstritt

If you just want your index.html to be the entry point into your angular app I think you need to serve it as a static asset. Try using express.static and pass it the directory that contains your index.html file. Try something like..

app.use(express.static('./public/'));
app.use('/*', express.static('./public/index.html'));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

express js routes how to get the root

From Dev

Express root get route overriding other routes

From Dev

how to get Express routes to angularjs files working

From Dev

How to protect routes in express.js?

From Dev

How to configure dynamic routes with express.js

From Dev

Express named placeholder routes on root

From Dev

How to setup REST API routes for CREATE, UPDATE, GET AND DELETE in Express.js?

From Dev

How to get different css files for different routes (express, node.js)

From Dev

Routes in express JS

From Dev

Express JS Routes

From Dev

Defining root and error routes in NodeJs/Express

From Dev

How to get optional language parameter from URL in Express routes?

From Dev

How to get functions from express routes for unit testing?

From Dev

How to separate routes on Node.js and Express 4?

From Dev

How to test Express.js routes with Jasmine 2.3 and SuperTest

From Dev

Express.js - How to Modify app.locals variables in routes

From Dev

How do I handle Express.js routes?

From Dev

Express.js dynamic routes

From Dev

Express js routes - overlapping params

From Dev

Express.js routes with Typescript

From Dev

Consolidating Routes in Express.js

From Dev

express js routes stop working and sending me could not get any reponse

From Dev

How to Avoid Repeating Passport.JS Code Used in Multiple Express.JS Routes

From Dev

Express.js - Single routes file that manages all the routes

From Dev

HTTPS express.js server and routes

From Dev

Move routes into files in Express.js

From Dev

Node.js express nested routes

From Dev

Express js routes not working as expected with MEAN stack

From Dev

Dynamic routes with Express.js -- is this even possible?

Related Related

HotTag

Archive