I had created server in nodejs and creates routes using express....
while calling that services from tomcat server i am getting error
can anyone help me how to configure that in tomcat
var express = require('express');
var app = express();
var port = process.env.PORT || 3000;
app.listen(port);
Related
Im trying to deploy angular app 13.2
ng build
This command generated dist folder
//Install express server
const express = require('express');
const path = require('path');
const app = express();
// Serve only the static files form the dist directory
app.use(express.static(__dirname + '/dist'));
app.get('/*', function(req,res) {
res.sendFile(path.join(__dirname+'/dist/index.html'));
});
// Start the app by listening on the default Heroku port
app.listen(8080,'127.0.0.1');
Using above started server, but finding this error in browser console
Any help...
I tried app.use : API's are not working getting 404
var express = require('express');
var app = express();
app
.use('/app', require('../app1/app.js').app)
.use('/app1', require('../app2/app.js').app)
.listen(5005);
I have a React and NodeJS app. Here is my server/index.js file:
const express = require('express');
const bodyParser = require('body-parser');
require('dotenv').config();
const app = express();
app.use(bodyParser.json());
const items_controller = require('./controllers/items_controller');
app.get('/items', items_controller.getAllItems);
const port = process.env.BACKEND_PORT; // 3333
const server = app.listen( port, () => console.log(`Listening on port: ${port}`) );
When I'm doing npm start it's trying to start React server on my backend server which is 3333 when by default it's 3000. Does anybody know a reason?
There are two possible reasons for this issue:
You might be having something running on PORT 3000(check if any process is using it)
If this is the case, react-scripts will find next available free port (which is probably 3333?) and start the server there.
You might have exported PORT environment variable.
If PORT environment variable is available react-scripts uses it to start the server.
I tried to connect angular front end with nodejs earlier I ran ng build on public folder of app and then ran localhost:3000. No error was given on compilation but app is broken now. Now do I achieve it? My folder structure is like this
client
public
app.js
client contains all angular code, public contains compiled code of angular
till I have also changed output path to ../public in angular.json.
And here is my app.js:
var express = require('express');
var path= require('path');
var cors = require('cors');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var passport = require('passport');
var app= express();
var port = 3000;
app.set('view engine','ejs');
//app.use(express.static(path.join(__dirname, 'public')));
app.set('views', path.join(__dirname, '/views'));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/api', routesApi);
app.get('/', (req,res) => {
res.send("Invalid page");
});
app.listen(port, () => {
console.log(`Starting the server at port ${port}`);
});
I think up to now you have a build of a running angular application and perfectly running node.js server.
What you have to do is host your client application. Follow the following steps to get this working.
Install http-server globally on your machine using npm install http-server -g command
Then run http-server /path/to/your/dist/folder. (You should get a dist folder after running ng build --prod)
Then run your node.js server.
And open your browser and go to http://localhost:8080
I have developed server Rest APIs using node and ExpressJS. Now I want to deploy this application on wildfly server so that my Client application can access the APIs.
What is way to achieve this? below is my app.js file.
var express = require("express");
var bodyParser = require("body-parser");
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
var routes = require("./routes/routes.js")(app);
var server = app.listen(3000, function () {
console.log("Listening on port %s...", server.address().port);
});
You can try heroku cloud, it's simple and free untill some limits but it's nice for testing
link
If you have vps you can:
Deploy code somewhere for example github
Connect to your serwer by ssh
Install node.js on server
Pull your api code from github
Install app dependencies (npm)
Run app