Node.js or Ubuntu Linux run cron on server start up - javascript

So I have a node server on Ubuntu and I want it to
unzip a file that gets uploaded from ftp,
read a text file inside, and then
save the information to mongodb every day at 4am.
I'm a bit confused on whether I should let ubuntu do that or have my node server do that because I feel like this is a little bit of both: unzipping files to folder is easier with bash and reading and saving to mongodb is easier with javascript (for me).
Any suggestion on how I can approach this?

If you use https://github.com/EvanOxfeld/node-unzip you can get the file and data from the zip file, then use node to save it.
Though you could also probably use both, use bash to unzip and get the file name then send it as a parameter to the node file and run it, all through bash.

Related

Is there a way to run a js. parser in python and retrieve the data?

Sorry if this isn't super clear, as I'm not quite sure how to go about this. There is a parser on github that allows you to listen to a game and then show its realtime data with a powershell command. How would I go about running the .js file in python and then gathering its information?
These are the instructions to run it that are given on the github page:
"### Reading live files
To use the above script, do the following:
Open a terminal prompt in the folder containing the script file and the package.json file
Run yarn to fetch the dependencies
Run node realtimeFileReads.js "C:\mirror\output\path" replacing the path argument with where your connected console outputs replay files to
At this point, you should see an output as you play games on the connected console."
If there are questions I'd be happy to answer, as I'm sure it might need some more context.

How to make an executable(.exe) that packages a nodejs server? (not UI-centric)

I have implemented a nodejs server that serves incoming requests to use the bluetooth services of the local computer. I want the nodejs server to be packed as an windows executable file so that I can distribute it. People should be able to just install/run that .exe which will install any packages required (if any) and run the server. How to do this?. I saw and tried node-webkit etc., but they are UI-centric, that is it can pack a nodejs application that opens a html page. But I want my server javascript file to be executed, like the way it is done in command prompt : node file-name.js. How to do this?
I've a server running with nodejs and for execute this I use a .bat file.
Create a .bat file
Inside of the file put:
cd path/to/server/
node índex.js
I used JXCore for this task in the past. It basically creates one executable that includes everything.
Unfortunately active development of is halted.
Solution:
You can use nexe for that.
Create a single executable out of your node.js app
Motivation
Ability to run multiple applications with different node.js runtimes.
Distributable binaries without needing node / npm.
Starts faster.
Lockdown specific application versions, and easily rollback.
Faster deployments.

How to upload nodejs project or install nodejs and npm modules on live server

I've made a real time chat application with node and socket io and it is running well in my local machine. But its time to run it on my live windows server. I can't understand to how set it up there. Do I need to upload the files to the server or I've to install node js and npm modules in the server and then upload the files. And how I can do these? How I'll run the command prompt as we do in local machine like node chat.js ? Any help is appreciated.
Thanks in advance.
You can use a deployment client like Capistrano or you can just upload your source files then run npm install (assuming your have node installed) followed by your commands to bring up the server. I'd suggest using a framework like meteor or sails to make deployment easier. Or using a cloud solution like heroku.
You can use Jenkins for deploying your app to server. Running bash commands and setting builds are much more easier.
Keep it simple:
Download and install NodeJS, NPM (here)
You need to establish a simple way to move your files to the remote server. Since you can run your code and do the development at your local machine, I recommend you to use github for this purpose. Set up a repository and clone it at your remote server. Then, you can always push and pull your changes using git.
You need to establish a simple way to run your code at the remote server. Since you use Windows, I recommend you to create a .bat file that does all the preparations and runs your code. In the simplest case, it would contain node path\to\project\chat.js. Then, run this file using a console. If you're going to use github, you probably should include this .bat file to your repository.
Good luck!

`fs.lstat` raises no error after I manually delete a file, but reading the file does

I want to submit to you this question:
If I delete a file manually (that is, not using fs.unlink in Node but using the GUI or a CLI command) after the server has already started, Node says that the file still exists when I use fs.lstat but if I try to read this file, Node throws ENOENT because the file does not exist.
I thought maybe the cause is that Node has an internal file list created when the server starts, and only when Node's filesystem functions are used to manipulates files and directories would this list be updated. Am I mistaken?
When you call fs.lstat node is going to request the information from the operating system. It is not going to fetch it from some internal cache.
This being said, it is quite possible to write a Node application that won't behave properly if files disappear after it is initialized. But this is not a fault in Node but a fault in the application itself.
I have found the bug!
At the server start, I create a folder.
When after the server start, I deleted this folder for a test (is a cache folder), I didn't remember that the file requested was in this folder and Node normally says "not found stupid"... ahahah sorry guys and thanks anyway

Running a local server with javascript

I want to create a simple Javascript program with a HTML interface. The program will run in Chrome. I will also use node-serialport and Node.js to comunicate with an Arduino. I have a HTML and JavaScript file done, but I have no clue how to run it, or how to implement Node.js or node-serialport, nor how to "start" the sever. Initially it will only be running locally, but eventually it may become a real sever. For now, how do I run all that locally?
EDIT: I'm using the sample code from http://brandontilley.com/2012/03/02/controlling-an-arduino-from-nodejs.html, with the CoffeeScript converted into JavaScript.
Lucas, glad you found the blog post useful; perhaps I should add this information to it.
Getting the sketch into your Arduino
Just fire up the Arduino application, paste in the sketch code, and hit "Upload." Should be all you need to do here.
Starting the Node.js Server
What operating system are you using this on? Finding out how to access your Arduino microcontroller via node-serialport will differ based on your OS.
In the source code, change the string value of port to be your Arduino's device (once you know it). Also, the script depends on Express and (of course) node-serialport from NPM, so run npm install express serialport in the directory where your JavaScript file is saved. Finally, run the file with node server.js (assuming server.js is the name of your file). Then you can access the server at http://localhost:8080.
You can use node.js to serve up HTML with Express. If your main Javascript file is called server.js, then run it by typing:
node server.js
at the command line.

Categories

Resources