I have to meteor application in local (admin and client). Applications run on different port 3000 and 3003. I want to use both app should use the same DB. export MONGO_URL=mobgodb://127.0.0.1:3001/meteor will be okay. But I would like to know any argument to pass with meteor command to setup environment variable to use the same DB.
If you are looking for a start script you could do the following:
In the root of your app, create a file called start.sh:
#!/usr/bin/env bash
MONGO_URL=mobgodb://127.0.0.1:3001/meteor meteor --port 3000
Then run chmod +x start.sh
You can then start your app just by typing ./start.sh
Related
I created a discord bot and am now attempting to run it off an Ubuntu Machine.
I installed the folders of the bot and NodeJs, here is what I used to install NodeJS:
sudo apt-get install -y nodejs
Then I used cd to select the directory, and started my bot using node index.js
The bot started, however when I went to close the putty and keep it running on the VPS the bot shutdown. Here is what the directory looks like.
I think the problem is that when you start the app in the putty window, that process is linked to the window and gets terminated when that is closed.
To avoid that you can use a host service like screen, tmux, nohup, bg and so on...
If you want to know which is the best, try looking at this question from the askUbuntu Stack Exchange.
The key concept is that you open a new window using the tmux command (or screen, ...), then run your bot like you always do. When you want to leave but keep the process runing, you can detach the session with a key combination, that changes from service to service.
If you want to access that window again, you can run a command that will "restore" your session, like
tmux list-sessions
tmux attach-session -t 0
The NodeJS instance is terminated when putty is closed. You need something to keep the instance alive. Try:
PM2: http://pm2.keymetrics.io/
or,
Forever: https://github.com/foreverjs/forever#readme
Recommended though is to run the node instance as a service that can reboot on startup. Try looking at this:
https://stackoverflow.com/a/29042953/7739392
The shell runs in the foreground. This means any scripts you start there will end once you end your session. A simple solution would be to run your script in the background by adding the & after the call:
node index.js &
A better solution would be to create a service you can ask the service daemon to run for you. However, adding the & should get you what you want for now.
I recommend using one of these two node modules - ForeverJS or PM2. I'll show you how to quickly get started with ForeverJS but PM2 would be very similar.
You can easily install ForeverJS by typing the following in your terminal:
$ npm install forever -g
You may need to use SUDO depending on your user's privileges to get this working properly. It is NOT recommended to use it in production due to the security risks.
Once installed CD to your projects file directory and like you typed 'node index.js' you will do something similar with ForeverJS.
$ forever start index.js
Now when you exit the terminal your NodeJS application will remain as a running process.
I'm beginning to learn web technologies and programming and I'm setting up my own local webserver. I have HTTPD, PHP, Python, MySQL all up and running on Windows. Now I want to add Node.js to the mix. I installed the Windows 64 bit installer. Now how do I begin? I have a basic Hello World script in a test.js file. But when I access this file in the browser it only displays as plain text. It's not executed. How to execute a Node.js script on the server?
Starting a node script is pretty simple. Just use your command line or terminal and execute the following command.
node /path/to/your/file.js
Doing so you'll start your node script. If you're going to start a server it's pretty much the same. Just keep in mind to define a server in your node file and start it. A simple server using express could look like this (You can also use a fully node way, this is just a simple example using express. You may check google for how to set up a simple node http server).
var express = require('express');
var app = express();
var port = 4000;
app.listen(process.env.port || port);
As you can see the specified port is set to 4000. You can simply adjust this by changing the value itself or passing in a node environment variable. To pass in an environment variable just start your server like this.
node port=3000 /path/to/your/file.js
This will finally pass the value of port to process.env.port which obviously will start your server on the port 3000.
you can use these packages to keep the file running so you won't have to login to server every time :-
forever
and you can just write :-
forever start app.js
nodemon
nodemon app.js
pm2
which is very useful , as it will auto restart your app when it crash or any error happens
pm2 start app.js
Your run your file: node server.js
Then it starts.
There should be specified in code on which port you run your server. Then it is accessible for example at http://localhost:3000/
As Quentin noted, I was thinking about "creating web server". Of course, you can run javascript code with Node.js without server. Then skip the part abot localhost, just use node test.js in console.
So, we've built a basic express node website
Trying to run the app with DEBUG=express_example:* npm start
With node DEBUG=express_example:* npm start
Also, tried inside node runtime:
http://localhost:3000/ is not connecting
Where are we wrong?
You need to create a variable called DEBUG with set command.
There is not command like DEBUG, it is a name of variable, so please try to run your server with set (to create variable):
set DEBUG=express_example:* & npm start
Try
DEBUG='express_example:*' npm start
Your environment variable was not getting set properly. Note that you can have many different environment variables this way
TEST=foo DEBUG='bar' npm start
We have deploy the MeteorJS code on Ubuntu server. We haven't created any client to access this MeteorJS service. First we wanted to verify the service are running properly. Can any one suggest the steps for check the deployment is correct.
We install Meteor on Ubuntu : curl https://install.meteor.com/ | sh
MonogoDB - Already install for NodeJS application - Its Working!
Copy the Code Meteor Code to server using WinSCP
Set the MongoDB path for Code : export MONGO_URL=mongodb://ip:27017/userDB
Run Command to start the app: sudo nohup meteor --port 3001 --production &
Thanks.
I have launched a localhost:207017 mongod 3.0.5 which is a completely separate mongodb than meteor's
I want to connect to it from meteor (which has a local mongodb).
I have seen in How do I use an existing MongoDB in a Meteor project? that we can use: export MONGO_URL=mongodb://localhost:27017/your_db to link "something" to my mongo server.
Question:
where is this mongo_url env variable stored ie locally in my meteor appli ? Is it specifically for the meteor appli I am dealing with or for all meteor.
how do I come back to the local mongodb of my appli
with the following code, no collection is created in your_db BUT I have a new collection (empty) called meteor_accounts_loginServiceConfiguration.
In meteor, I am using todo example from meteor doc site
.js file
Tasks = new Mongo.Collection("tasks");
if (Meteor.isClient) {
// This code only runs on the client
Template.body.helpers({
tasks: function () {
return Tasks.find({});
}
});
}
.html file
<body>
<div class="container">
<header>
<h1>Todo List</h1>
</header>
<ul>
{{#each tasks}}
{{> task}}
{{/each}}
</ul>
</div>
</body>
<template name="task">
<li>{{text}}</li>
</template>
Anybody has a clew how all this is setup and working and how to fix it?
Best,
G
Environment variables can be set on the command line as you launch the application, so you do not need to set this in your overall shell environment. Doing that would mean either it is global for that shell or global for all shell sessions depending if you set that permanently.
But a simple migration for me is just a few steps:
Start meteor application in one window
In another window connect to it's local MongoDB by the running port. ( in this case on 3001 ), just to check:
mongo --port 3001
After reporting connected and exiting the shell, then I run a mongoexport and mongoimport to copy the desired collection:
mongoexport --port 3001 -d meteor -c cards | mongoimport -d meteor -c cards
I am just piping the output from the export to the import which is simple. Also I am choosing to keep the same database name, but you can change if you want. Repeat exports for each collection you want.
Stop the meteor application which stops the local server, and then resart with the environment setting issued before the meteor command. Again, I put everyhting in the "meteor" database, so that is what I am connecting to:
MONGO_URL="mongodb://localhost:27017/meteor" meteor
When the app is started up, it hapilly reads the data from the migrated collection and displays perfectly.
For the paranoid, if you did not notice the output in the meteor startup which did not report a local MongoDB starting, then you can check the running processes and see that only your "global" MongoDB is the only instance running.
Or of course if you pointed to another machine, then there is no MongoDB running on the application server.