I have a node.js file that runs locally when I run it and it sends the user a text notification via the Twilio service. However, I'm trying to deploy it to my AWS Ubuntu server (EC2) so I can use it now on my actual website, but I'm not sure how to upload a local file to my instance like I did when I was following this tutorial (https://hackernoon.com/tutorial-creating-and-managing-a-node-js-server-on-aws-part-1-d67367ac5171) when I initially mkdir server and then cd into it which ultimately contained index.js, node_modules, and server file.
Now on my local folder, it also contains a folder called node_modules that currently has an express folder and a Twilio helper folder. So would I have to put the Twilio folder within the node_modules folder in AWS and is there a way to do this through the Terminal?
Additionally, I was curious if my app.js (Node) file would even function if my Twilio file is hosted on a GoDaddy server? I hope I made sense and any help is appreciated.
You can use the rsync command line utility (available on Linux, Mac, but also on Windows with Cygwin).
The way you'd use it is:
rsync -e 'ssh -i YOUR_AWS_KEY.pem' -avh /path/to/your/local/folder YOUR_AWS_USER#YOUR_AWS_HOSTNAME:/your/remote/path
Related
I have a directory structure like this for an AWS Lambda layer.
main > nodejs > node_modules
I have a test.js file to test functionality before uploading to AWS. Is it possible to have my test.js file in the Main folder instead of the nodejs folder and still have it pick up the modules in the nodejs folder?
I'm asking because you compress the nodejs folder to upload for the AWS Lambda Layer but I don't want to include my test.js file in the archive.
UPDATE: An answer below helped my find the solution. You just enter the full path to the module in require.
require('./nodejs/node_modules/my_module');
Set NODE_PATH environment variable when you are running test.js
NODE_PATH='yourFolder'/node_modules
source
One way is to load the script and execute it using the --eval flag:
cd nodejs
node --eval "$(cat ../test.js)"
I tried to run index.html inside dist folder in the browser but its not working, unlike the angularjs application where we import the script file in the index.html and the application simply works.
Why we can't do that in the Angular Project as there are some javascript files which are imported in the index.html same as any other javascript project.
You can do that in Angular application as well. You need to install http-server for that.
Follow the below steps-
Install http-server from npm server using following command-
npm install http-server -g
Generate the build in dist folder using command-
ng build --prod --aot --output-hashing=none
Run the command to run the project from dist folder-
run http-server ./dist
This will start serving your project from dist folder.
When index.html is being loaded directly in the browser, it doesn't use the http protocol. It is being loaded over the local file system over file:/// Browsers don't allow direct access to the .js files from a file system because of the security reasons.
The file system is not providing needed features of a server which is required. Github comment with some more details.
At a minimum, a simple static HTML server is required to run the Angular applications.
Angular apps are perfect candidates for serving with a simple static HTML server. You don't need a server-side engine to dynamically compose application pages because Angular does that on the client-side. Read More
I've deployed my app on Heroku and I have an express script that should wait for a post request. I need to run it separately on Heroku. When I open the console on Heroku and type:
heroku run bash node scripts/start_express.js
I get the following error:
/app/.heroku/node/bin/node: /app/.heroku/node/bin/node: cannot execute binary file
How do I use node to run my js file on Heroku?
The node buildpack for heroku will automatically look for npm start script in your package.json file. That is where you can specify which file to serve up. Check this article out for some help on node and heroku https://devcenter.heroku.com/articles/nodejs-support
I have a simple Angular 4 frontend as well as a node backend which is hosted separately on Heroku.
I deploy my Angular app by running ng build and copying over the contents of the dist folder to the server.
I have since then decided to integrate the backend into the front end so it's all just one project instead of two.
I can easily run node server.js on the root and it runs perfectly on my localhost.
But how can I deploy this to my server? I obviously can't just ng build and copy over the dist folder because that only builds the client folders and files.
Could I just copy over the server folder which holds the routes as well as the server.js file along with the client files and then somehow tell the server to run server.js when the site is loaded?
I use FileZilla to transfer my files onto the server.
Questions:
How do I deploy my angular/node app with FileZilla?
Which files/folders to I copy over with the client files?
If you are using Angular CLI, run ng build command to generate the dist folder.
Copy the dist folder to the backend server nodejs project.
Serve the dist folder using your Nodejs code.
If you are using ExpressJS. This can be done in a single line
app.use(express.static('dist'));
Install Heroku CLI and follow the tutorial to deploy your app: Heroku NodeJS Tutorial
You don't need to build the node app. Node runtime can compile the javascript on the fly.
The build step in angular packages up your code into one file. There is no equivalent in node as there isn't any point. The reason angular minifies and packages a file is so you can download it quickly. You never download the code from node.
On Heroku it's really easy, you don't need to copy anything over just run git push heroku master from the root of your node folder as per the instructions here https://devcenter.heroku.com/articles/getting-started-with-nodejs#deploy-the-app
Just make sure that in your package.json you have all the modules you rely on. It might work locally if you have npm modules installed globally but they also need to be in the package.json so heroku can download them by running npm install
I've got a small node.js and socket.io project that i would like to run online on my server. I used jade for my files, and packaged it complete using npm install. So everything is in my local folder. I can also run it locally which works.
But i want to connect my phone to control my browser and i can't connect my phone to a localhost. So I need to run it online.
The problem is when I put it online i've got a index.jade file. This one doesn't get recognized by the browser as webpage. So i only get a forbidden page when i go to http://www.woutervdkamp.nl/iphoneconnect/views
my folder structure is like:
└── httpdocs
├── iphoneconnect
| ├── node-modules
| ├── express
| ├── jade
| └── socket.io
├── package.json
├── server.js
└── views
├── index.jade
└── mobile.jade
Do I need to use a special host for it? Or can someone point me in the right direction! Thanks in advance.
I'm trying to make something like this:
http://sportyfinger.lecoqsportif.com/uk-en/connexion
If anyone got a good tutorial for that would be nice! I only would like to know how to set up the connection between iphone and webbrowser! Already got something right now but it's bit slow.
Greets,
Wouter
First of all, you might got lost in understanding what is happening.
Your current method is to serve node.js project as static site, using Apache.
That is not going to work, your node.js project consists of instructions, and to parse these instructions you need a program. That program is called node.js, not Apache or anything else.
Most webhosting companies you will find do not support node.js at all. The solution is to find a specific node.js hosting service or virtual/cloud hosting instead.
Some of appropriate for the task hosting companies 1 are: Heroku, OpenShift, Digital Ocean.
After choosing, you will have to setup simple Linux server using the supplied colorful guidance and then install node.js program before running your project.
After you have Linux ready, you have to install node.js there and run your project the same way as if it was on localhost.
Summarizing all I said:
Find the hosting company with node.js or shell access.
Setup linux OS (I suggest Ubuntu) through the hosting company tools. (easier than it sounds, don't worry)
Run the following commands to get node.js on your fresh linux server:
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install python-software-properties python g++ make nodejs
Copy the project files to the server
Navigate to the project location on the server and run it as you would do on localhost: node.js server.js
1 - Comparison of Hosting companies by #Vinz243
I am also doing some simple node.js web app recently and I think Heroku is a very friendly hosting websites for new developers.
For hosting on heroku, you do not need to run sophisticated bash commands. The method that heroku recommends is that you install a tool called heroku to the terminal but it is not necessary. Just add a remote to the heroku repository(which you can create on their website) and push your source code to that remote repository and you can see from the command line that heroku will automatically detect, compile and host the node.js web application for you.
git push heroku master
btw, Heroku also has database and logging add-ons.
For your reference:
https://devcenter.heroku.com/articles/getting-started-with-nodejs