Azure Node.JS Tutorial Default Template Engine - node.js

Im following the tutorial here. I when trying to run the project at this point. I get an error saying that there is no defined templating engine. The tutorial has us remove the app.use
Below is my console error when trying to go through the tutorial. Just to be sure I went back through it three times. I get the same error. I notice in the History.md that this was addressed but I cant figure out what if anything i am supposed to do with that info. Can you advise?
This is the tutorial: https://azure.microsoft.com/en-us/documentation/articles/documentdb-nodejs-application/
I get the error on trying to run npm start to see the todo UI. When I run start at the beginning of the tutorial, it works.
Thank you.
Kaona (master *) todo $ npm start
> todo#0.0.0 start /Users/Kaona/GitHub/todo
> node ./bin/www
/Users/Kaona/GitHub/todo/node_modules/express/lib/view.js:62
throw new Error('No default engine was specified and no extension was provided.');
^
Error: No default engine was specified and no extension was provided.
at new View (/Users/Kaona/GitHub/todo/node_modules/express/lib/view.js:62:11)
at EventEmitter.render (/Users/Kaona/GitHub/todo/node_modules/express/lib/application.js:569:12)
at ServerResponse.render (/Users/Kaona/GitHub/todo/node_modules/express/lib/response.js:961:7)
at /Users/Kaona/GitHub/todo/routes/tasklist.js:27:17
at /Users/Kaona/GitHub/todo/models/taskDao.js:43:17
at Base.defineClass._toArrayImplementation (/Users/Kaona/GitHub/todo/node_modules/documentdb/lib/queryIterator.js:187:17)
at /Users/Kaona/GitHub/todo/node_modules/documentdb/lib/queryIterator.js:183:26
at /Users/Kaona/GitHub/todo/node_modules/documentdb/lib/queryIterator.js:234:17
at successCallback (/Users/Kaona/GitHub/todo/node_modules/documentdb/lib/documentclient.js:2069:17)
at IncomingMessage.<anonymous> (/Users/Kaona/GitHub/todo/node_modules/documentdb/lib/request.js:84:13)

Per #ryancrawcour #larrymaccherone's direction. The solution is to add app.set('view engine', 'jade'); to the app.js file in the tutorial. See Error: No default engine was specified and no extension was provided

According to the error, I guess your machine is a Mac, but I think my steps below on linux that's similar with yours on MacOS.
The tutorial sample shows a local node app created by express generator for using Azure DocumentDB.
So the first step is creating an Azure DocumentDB instance on Azure new portal. I think it's simple, and copy the connection information of the DocumentDB created for the express app.
To create a express app like the tutorial doing, I did the steps below.
Command npm install express-generator -g
On MacOS, may need to add the prefix cmd sudo because it's for global env, see http://expressjs.com/en/starter/generator.html).
Command express todo
Generate a empty express app via express generator
Command cd todo && npm install
installation for dependent libraries registed in the package.json
Now, you can command npm start in the dir todo and browse the url http://localhost:3000
Command git clone https://github.com/Azure-Samples/documentdb-node-todo-app.git from Github project https://github.com/Azure-Samples/documentdb-node-todo-app and copy the files of the path src of git repo to the dir todo.
Edit & configure the config.js with the connection information of your DocumentDB.
Hope it helps. Best Regards.

Related

How to combine vue-cli development mode with server-side api?

I'm new to vue and kind of confuse here.
I'm using vue-cli to build a vue app, I understand I can run a development server with npm run serve which is referenced as a script in my package.json for vue-cli-service serve
But my app need some data coming from a local node.js server. I cannot request this server from development mode because it's running on a different server.
To make my app work I'm obligated to build for production with
npm run build
Then to ask my node server to render by default the produced index.html file.
How could I combine development mode and my node server?
What would be the best way to make this work?
Thanks a lot
I stumbled across this, and found the answer buried at the bottom of the comments list, so I thought I'd highlight it.
This answer is taken from #Frank Provost comment, which really should be the accepted answer. As mentioned in his link https://cli.vuejs.org/config/#devserver-proxy all you need to do is create/edit vue.config.js file in your (client) project root to include this:
module.exports = {
devServer: {
proxy: 'http://localhost:3000' // enter dev server url here
}
}
Then start your dev server as usual from your server project:
[server-root]$ npm run dev
And run your client project from vue-cli project
[client-root]$ npm run serve
Then when you visit the client url (usually localhost:8080) all api requests will be forwarded to your dev server. All hot module replacement still works on both client and server.

Need help getting simple node.js express to run

I'm trying a simple sample of node express that I copied from online. The script is below which I think is pretty standard.
var http = require('http');
http.createServer(function(request, response)){
response.writeHead(200);
response.write("hello");
response.end();
}).listen(8080);
console.log('listening on port 8080...');
I used the bash on ubuntu on windows command as follows:
npm init
node SampleServer.js (the name of my file)
When I do this, I expect some response from the command line. But when I enter the "node SamplerServer.js" command, nothing happens. When I direct the browser to port 8080, I get an error message as well.
I'm using nodeclipse and the installing that on my machine was pretty complicated. Prior to any of the steps above, I created an express project in eclipse ide. It seems to perform a lot of pre steps but in the end, I think I'm getting some of the error messages below. I'm mentioning this because I'm thinking perhaps I installed one of the modules wrong.
enter image description here
Start with simple stuff...
Use express-generator to create simple app by the following command
1-> npm install -g express-generator with root or Admin access
2-> Run express demoapp.
3-> Navigate to demoapp
4-> Do npm install
5-> Run from command with npm start: it run by default on http://localhost:3000
Hit that URL from Browser

How to install node.js and create project in Eclipse

The steps I've tried:
1.(OK) install node from official website: https://nodejs.org/en/download/
Result: I'm able to open cmd(in any location, type node then use commands like "console.log" and it prints my messages)
2.(Failure) install express using npm install -g express from cmd gives me an error(picture attached
3.(OK) I've succeed installing express using the following command npm install express (without -g)
4.(OK) Writing a simple Hello World program works. Javascript file:
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");
5.(Failure) However, I wanna run a bigger project, where besides one js file, I also have an index.html file. If I move both files to node installation directory, everything works. But I wanna be able to keep my projects somewhere else. If I try to run with node C:\Users\marius\Downloads\chat-example-master\indes.js I get the error: Cannot find module express. Thus it seems that when I installed express without "-g" I got it working only in node directory.(let me know if you have any doubt).
6.(Failure) When creating a Node.js project from Eclipse, I choose empty project, no template, then add a single and simple js file(the one with Hello World), right click on project name -> run as -> run Configuration -> Node Application -> New -> add my .js file -> Run. I get the following error:
Exception occurred executing command line.(steps from http://techprd.com/how-to-setup-node-js-project-in-eclipse/)
Cannot run program "node" (in directory "C:\Users\marius\workspace\FirstNodeProject"): CreateProcess error=2, The system cannot find the file specified
To recap: What I want is to be able to run node projects located anywhere with "node" in cmd and to create node.js and express project and run them from Eclipse.
Please let me know if you need more information.
Just to let others know if they come across this issue. I can run express apps from anywhere but in the root folder of every app I have to npm install express.
In Eclipse all you need to do is: Window->Preferences->Nodeclipse->uncheck "find .Node on PATH" and insert into Node.js path input your node.exe location (in my case: C:\Program Files\nodejs\node.exe)

how to use the webodf editor in localhost with node.js

I did not find any tutorials to how to run the webodf i read his apis and source code i am getting how to start it can anybody share the idea.
- WebODF version 0.5.10-8-gf5949f3
-- Found Java: /usr/bin/java (found version "1.7.0.91")
-- external downloads will be stored/expected in: /home/peoplelink/build/downloads
-- Installed Node.js found: /usr/bin/nodejs - 0.10.25
-- good Node.js found: 0.10.25 (0.10.5 required.)
-- npm found: /usr/bin/npm
-- Android was not found: APK will not be built.
JS file dependencies were updated.
-- Configuring done
-- Generating done
-- Build files have been written to:
i got this but i am not getting to webodf.js file in it i am missed out anything.
I am not not sure what you currently have . But This is how you can configure an application using node.js to serve html files and view/edit odf files.
Lets Start with your Node.js Server
First Create an index.js file(name it whatever you want)in our application directory,then initialize node application using node init.
We will have following folder structure : -
./ document-editor
../app (our html code and libraries)
../index.js
../package.json
../And some other auto-generated files.
Include all the modules necessary.We are going to use Express,Multer and
other util libraries.
var express = require("express");
var multer = require('multer'); //for file handling
var util = require('util');
var app = express(); // init express app
Configure Routes and Html files to be served on user request to you server.
app.use(express.static('app')); // use this as resource directory
//APP ROUTING URL => FUNCTIONS
app.get('/', function (req, res) {
res.sendFile(__dirname + "/app/index.html");
});
// this means when we get a request on 'myAppContext/' url provide
index.html
Start the Server
//START THE SERVER
app.listen(3000, function () {
console.log("Listening on port 3000");
});
Note* : Make sure you have node.js envoirnment installed on your system before you start.
Now Lets Look at how we include webodf to our application.
First create a directory in your main folder(we name it 'app'), where all
the html,styles and scripts..etc will be stored.
/app (our html code and libraries)
../index.html
../script
..wodotexteditor-0.5.9(folder)
..myScript.js
../styles
../images
../And some other files.
Create an index.html file and include webodf and/or Editor JavaScript libraries(Contains Webodf included in build... so need to download separately).
Create a container element and local script necessary to run webodf editor.Make sure to add a odt file to directory for you test or you can use the one which comes with wodo-editor.
You can refer this link for creating a local webodf editor using wodo-text-editor and complete the above to steps(2 & 3).
After we have done the above things,we will go into our root directory and run 'node index' command.... and that's it folks.
Just hit localhost:3000/ and you will see a workable webodf editor.
I hope this helps to get started with node.js and webodf. I will soon create and full application with open/edit and save features using webodf and node.js.
Thanks :)

Running node.js server with mongodb error

I'm still new to node.js and mongodb. Now I'm trying to solve this problem.
I have instructions to run my server without any problems, I follow them and yes my server works. But when I switched the server off then run it again I face this bug:
[vagrant#localhost ~]$ node /opt/inapsrv/app/app.js
app-api listening at http://0.0.0.0:7000
/opt/inapsrv/node_modules/fileupload/lib/modules/file.js:23
throw error
^
Error: ENOENT, mkdir 'data/imagex/'
And here is the line of the directory above taken from app.js file:
var imagePath = 'data/imagex/';
I tried to:
make vagrant and mongo users as super users and they have the root permissions.
to run "sudo node /opt/inapsrv/app/app.js"
run "forever /opt/inapsrv/app/app.js"
and it didn't work.
I don't know why it successfully ran the first time, and then it didn't!
Any help?
I suspect you're using node module fileupload for the upload job. The source code fragment in fileupload that throws your error can be found here.
The problem with the code used in fileupload module is that it does not create recursive directories since fs.mkdir is used. To fix your issue try to create the upload directory or at least data upfront. You could do this by a npm script, in app.js using the mkdirp or simply by a shell script.
The problem described is not related to mongodb or mongoose.

Resources