How to deploy node.js app onto a production server? - node.js

im new to node.js and have struggled to find information about deploying apps.
Say that I have written a small one file node.js app and would like to deploy it onto a prod server. If I deploy the app.js file alone I cant use "node app.js" to run as the app is missing package.json and the node modules. But deploying all these files/folders to the server seems like the wrong way to do it as it would take ages to transfer all the node_modules.
The only resources that I can find online use localhost node server which doesn't really show what I need. I'm using MobaX to deploy to a specific IP if this is useful.
Sorry if this is a stupid question, most of my experience is in front-end so haven't had the opportunity to play around with this and don't have anyone to ask for guidance.
Please don't mark down the question, I will happily edit the question if any feedback on doing so is provided.

Related

I don't know how to deploy this

I'm relatively new to StackOverflow and deploying. So be patient if this isn't the place to ask about this, any kind of help will be truly appreciated.
The thing is, I have a web app with a Front End made with ReactJS, a Backend with Node and Express, and backed up by MongoDB.
The app is a bit simple, you can login/logout, post photos/gifs, have your own profile etc.
As of now, My React app communicates to the backend with a Proxy, the images are a static folder served by express (so that its easy to fetch the images on react), and so far the tests went good, I set up Mongo Atlas so that I don't have to worry about that in production.
The point is... I don't know exactly where or how should I deploy this, I'm considering using Heroku but since I don't know if it supports local storing, and I'm not sure if it'll work, same for Netlify. I've been thinking of composing up docker images, renting hosting on Linode and deploy the images there.
So far my project tree looks like this
Project -> .git
client->React Stuff
server->Node Stuff + Images folder
//each with their own package.json and configs/env
If you have a document or a video that would help me know about deployment, I'll really appreciate, and also if you think that I should use Heroku/Netlify/etc or just wanna leave a msg , please do so!, tyvm in advance
From what you mentioned it sounds like Heroku should do the trick. Heroku uses git to store files. Here's a guide that should help you set it up

Deploying mono repo to Heroku, Node.JS, Angular 9. Heroku CLI

Having a bit of an issue with Heroku. I've always uploaded in one directory, but this time I wanted my folder structure to be a bit more, well structured. The problem is I can't seem to upload to Heroku like this.
I have a directory containing a folder called "client" which contains my angular 9 application and I have a folder called "middle-tier" containing the node.js server application.
I can't figure out how to push this up and allow it to work. The node application serves the angular application.
Everything works locally I just have no idea how to push this up to Heroku servers.
Please see attached screenshots of the structure.
Below is the error message I'm getting. Which I tried to fix by running git init again in the root of the structure. And then running the command to have a node.js build pack. Which was to no avail this also did not work and produced the same problem.
I have tried to include as much detail as I can but if there is anything else I can provide please let me know. I've spent quite some time building my application and am quite eager to deploy it!
Thanks for your time guys!
In short, with multiple discussions with Heroku support line, at the moment it is impossible to upload a mono repo to a single Heroku instance.

Node.Js app cannot be deployed to Heroku successfully

There's this tutorial which has a working chat app. You can find the chat app on GitHub.
I'm trying to deploy the git code to Heroku without success.
The GitHub is separated to client/server architecture so it requires to start node server and ng serve to client. Do I need 2 dynos for it? Do I need to edit the Procfile? The server is using process.env.PORT but the client one is hardcoded.
I'm very new to Heroku and Node.js so any help is meaningful to me.
The GitHub project that you ask about is pretty complex and it doesn't seem to have ane Heroku deployment instructions, without knowing the project it's hard to give you any concrete solution, but I'll try to answer in general how such applications are usually deployed and hopefully it will help you solve your problems.
For applications like this it is common to split the backend and the frontend part and have it deployed and hosted separately, either as two separate dynos if you want to host both on Heroku, or e.g. hosting the backend part on Heroku and the frontend part on Netlify or a similar service.
Another option could be to make the backend serve the frontend e.g. on the / path while having all of the backend endpoints available as /api/* or something similar (or on a different port but this is not possible on Heroku). Having it on the same host and port but with a prefix for the api has the advantage of simplifying the CORS related matters, as the origin is the same so no cross-origin issues arise.
If you're using WebSockets then it is slightly more complicated - make sure to read:
https://devcenter.heroku.com/articles/websockets
but either way you can still move your frontend to Netlify or something similar and keep the backend on Heroku if you want.
It's hard to give you any more specific answer to this question. I see that you are new here, so next time try to write a more specific question and narrow down the problem so that you can show a small code example that people could actually read and help you.

Angular CLI Node Express.js

I come from the LAMP world. Greetings. 🖖
I'm trying to get started with the new Angular and Node.js. I already have Node and an Express server installed on my machine. Now I want to use Angular as I start building my app.
One thing I don't understand is why the Angular CLI is spinning up a server to "run the application" and why it seems we have to setup proxies and do other things to get it to work with Express.
When I think of Angular, I'm most familiar with AngularJS as part of my LAMP stack workflow. All I do here is serve it as a .js file and serve it from the same webserver that is serving everything else. Why is a client-side script getting its own server? How is it different from Express and how does it fit in with Angular Universal, which I would like to use to take advantage of SSR.
I'm not looking at how to get it all to work, I can copy and paste and read docs just fine, I'm trying to understand the fundamental concept here. The Angular docs don't explain why they are asking you to "serve the application". Is it just to test it? Why would I have two servers in development and one in production, shouldn't the dev site mirror the production site as best as possible?

Deploying Sails to a standard web server (Windows)?

Today I discovered Sails and have been watching a few tutorials. One thing I can't seem to work and find out is how to deploy it to a standard web server, like for example via an FTP client. I've seen the tutorial on how to deploy it to a Heroku account, but this isn't really what I'm after, as we already rent a Windows 2012 server.
I've got a feeling I'm completely missing something here, so can someone please help me out :)
Many thanks
You can transfer all files via FTP to your Webserver (include all node-modules).
But you have to make sure NodeJS is installed on your server. Than login into your Server (e.g. via SSH) and start your Sails-App (node app.js)

Resources