CLI based node chat app - javascript

I am wondering how I would go about making a command line interface chat app using nodejs. I could just make one using http and then use something like phantomjs to read it back into the terminal. However I am sure that there is a better way to do this.
Thanks!
-Zoe

Try this:
https://code.tutsplus.com/tutorials/real-time-chat-with-nodejs-readline-socketio--cms-20953
Node.js has an under-appreciated module in its standard library that is surprisingly useful. The Readline module does what it says on the box: it reads a line of input from the terminal. This can be used to ask the user a question or two, or to create a prompt at the bottom of the screen.
You can then use Socket.io as the server.

Node.js is a server-based Javascript.
It will be better if you can use another programming language for client and connect it to NodeJS Server.

Related

Can NODE.JS library be accessed from the root directory of a website?

So, I'm making a quiz, and I've been wanting to save my answers to a text file. I want to use "Node.js", and I'm worried about this: They only offer an installer to install Node.js on your computer. Since I'm not working with servers or anything like that, and I'm just a hobbyist, the people I might first give this to may not have Node.js installed on their computer. Please do note that this is for a website, not a program.
Is this kind of thing possible to do without the use of a hosting service or a server? :
const lib = require('./libraries/NODE')
If it is, how would I do it?
Thanks for any help!
There are two options for you:
I would suggest using something like Electron- which will wrap the node runtime for you - https://www.electronjs.org/docs/tutorial/first-app which you can distribute to people. This will open up all the nodejs related functionality and more for you.
Another answer at SO though old, suggests using window.name vs writing out text files - Javascript/HTML Storage Options Under File Protocol (file://)
You cannot import nodejs runtime into the browser running on a file protocol.

Running NodeJS Code from HTML

So I have just been getting into learning NodeJS as part of learning how to build a webscraping tool for a project I wanted to make.
I have all the content I need from the NodeJS file when I run the file directly through the terminal, but I wanted to know how to run the code directly from a website I am building to display the content I get from webscraping.
Any and all help is appreciated!
(Also I am new to stackoverflow, so if you need any more info then I would be glad to help!)
Since Node.js runs on server side, you need to call the Node.js server through ajax and get the response back.
This website shows how to do Web Scraping in Node.js, now when you get the data pass it as a response to the browser.
You may also check Express.js which gives you "Fast, unopinionated, minimalist web framework for Node.js".
So you have working node application written in javascript. Perfect.
Now you want to run that in browser mode. you can use browserify for the same. Browserify will package all the nodejs module in a bundle and let you require from the browser.
Not exactly sure if this is what you are looking for, but you should look into a cloud9 space (its free) and using express to render the HTML. It's pretty straightforward.
I think Nodejs tutorial in tutorialspoint [http://www.tutorialspoint.com/nodejs/] is powerful solution. It is just advice.

How to convert a Node.js app to exe?

Simply put, how do I compile/create and "exe" file that when you click on it, it will open console for you and type in the node "something"
There is a question about this regarding batch, but I really don't want to do anything batch because then you have to deal with filepaths, installing node... etc. Thank you for your help.
nexe says it will create a single executable out of your node.js apps.
https://github.com/nexe/nexe
You can boundle electron application
Write in html, css, js and distribute to any platform
http://electron.atom.io/docs/tutorial/application-distribution/

How to update a node.js app remotely & automatically

I need to set up automatic remote updates for my app built on nodeJS (not the nodeJS itself).
In my specific case I can't distribute my app as SaaS, so I have to share a copy of app with each client.
I've checked related topics here, but haven't found helpful ones.
Here are a few related questions: one, two
I don't know how to set it up, but I have a few ideas:
old-school way (?) :
use unix cron + shell (or php) script to make «check-request» to «update-server»,
stop nodeJS instance,
replace files with newest ones from tarball,
run nodeJS instance with my app : from shell(?)
It may work if I use my own server, but how can I do the same on, for example, Heroku ?
Overall, it seems weird a bit.
two nodeJS instances way (?) :
use unix cron + another nodeJS app which checks updates on update-server,
then stop one node instance from another && update files
start one nodeJS instance with my app from another : how???
— Is here something else?
— How do folks solve that problem?
— How to realize, for instance, functionality like «Update manager» in Wordpress for nodeJS based app?
What you're talking about is CI (continuous integration), there are many tools that can help you in the process but they essentially do the same thing.
Detect a change in the code
Pull changes
Build the project
Run tests if there are any
Deploy to the server
— How do folks solve that problem?
Folks use Jenkins, bamboo and many other auto deployment systems.
If you're using node with pm2 you can use kinematic that has that build in (one-click deployment feature)

Possible Autoit-like JavaScript macros?

The title says it all. Is there a way to write macros in JavaScript to achieve a similar functionality to that of Autoit? I just would want to manipulate files on my own computer (offline) and could easily do it with autoit, but since I am currently learning JavaScript -- plan to develop in Node.js -- I figure it wouldn't hurt to get the extra practice.
Thanks guys!
Use an application which supports JavaScript as a shell scripting language, such as the following:
JsRoboKey
PowershellJS
PowerChakra
RemoteNodeJS
JScript + WSH
JavaScript Shell Scripting with JSC
QtScript: QScriptEngine
Part I: How to Choose a JavaScript Engine for iOS and Android Development - OpenAphid-Engine
nodejs has a module which do autoit things --
nodejs install autoit
var au = require('autoit');
au.Init();
au.Run("notepad.exe");
au.WinWait("[Class:Notepad]");
au.Send("Hello, autoit & nodejs!");
NodeJS is a very powerfull platform, it is extensible and opensource.
There is no problem to run local scripts to do everything you need using JavaScript (see standard FileSystem library docs). You can also try to look in NPM(NodeJS package manager).
Assuming you have AutoIt installed (say in folder C:\AU3) and this folder in the PATH, you can add
extension '.AU3' to the PATHEXT environment variable, and create an AutoIt script called, say,
hello.au3 with just a silly line:
MsgBox(0, "Warning", "Hello, World!")
Now, simply typing the command 'hello' will execute the script, displaying the silly message in a modal message box.
Next, create an equally silly Node.js script, say, MyWarn.js - in the same folder:
var oCP = require("child_process");
console.log("Starting...");
var oNP = oCP.execSync("hello");
console.log("Done.");
Assuming Node is also in the PATH, try this command:
node MyWarn
So ... we get the benefits of Node (for its jit), and the benefits of AutoIt (for its GUI handling.)
The problem is getting the two to communicate. Personally, I use a RamDisk to pass small files...
Javascript can't write to a file on your local machine remotely.. Its almost the same as HTML in a view model.
It can however perform some executions of other scripts via AJAX for example. But thats on server again.
It might be worth a look to read on server && client side differences.
im not 100% sure but node might offer another outlet on this but it would still be server side.. Not locally.
The Server - This party is responsible for serving pages and handling the logic | Code behind.
The Client - This party requests pages from the Server, and displays them to the user. On most cases, the client is a web browser.
The User - The user uses the Client in order to surf the web, fill in forms, watch videos online, etc.

Categories