w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Run nodejs command line module to output in nodejs web server?
you could have 2 node instances. One the http server and the second instance the command line instance to run jasmine. The http server instance would spawn the command line instance. Then you could register a GET route on the http server such as someexample.com/runtests which would call the tests and wait for the tests to finish and respond with the console output. This is sort of unorthodox, but there wouldn't be a direct way to run command line applications through the browser without modifying their source.

Categories : Node Js

Nodejs cron plugin vs running nodejs script from crontab
The main difference between the two methods in my opinion would be the level at which you want to schedule job. When using crontab your jobs are scheduled by the cron daemon that runs on the system. node-cron on the other hand is a pure JavaScript implementation of cron. So system is not responsible for running jobs but your V8 engine which executes it. Jobs will be run as long as your js application runs. So why would you use one or other ? That depends on the purpose of your job, where is it best tethered . If job is a maintenance job for system run it via crontab. If you want to run a function in node.js periodically use node-cron. If you want to run a bash script you would want to use crontab. So how you want to do it via system (bash) or JavaScript is upto you.

Categories : Node Js

nodejs conflicts with node (re installing nodejs)
You may be able to use my pre-built packages which are available here: https://launchpad.net/~chris-lea/+archive/node.js They install a /usr/bin/nodejs binary and then create a symlink from that to /usr/bin/node. If you are going to use these, be sure to remove any vestiges of any previous installs so that the system is using the correct binaries.

Categories : Javascript

How to improve phonegap SQLite performance, and what are the differences between Storage API and SQLite plugins
Although this posting isn't directly aimed at Cordova based applications, there might be some useful information in this posting. I do both native and Cordova based mobile programming and I find that SQLite is generally the same animal regardless of OS, Hardware or development platform. Hope this helps   How do I improve INSERT-per-second performance of SQLite?

Categories : Performance

SQLite/ADO.NET- Data Adapter doesn't write correct number of rows to SQLite file
As it is the code posted here is correct, the problem with fewer rows is from exiting the application before the inserts are done. The issue with the integers showing up as decimals was due to the tool being used to view the SQLite file, not the actual database itself.

Categories : C#

Converting sqlite to sqlite format inside Titanium Appcelerator
You can use the sqlite3 command-line tool to convert between text files containing SQL statements and SQLite database files: sqlite3 newfile.sqlite < oldfile.sql sqlite3 oldfile.sqlite .dump > newfile.sql

Categories : Sqlite

SQLite: Difference between java/jdbc-sqlite and python/sqlite3
Python is written in C and has the "sqlite" executable, also written in C, linked in. There is no marshaling of data, or conversion between formats as both Python and the underlying sqlite library are using the same data types and encoding which arenative to whatever platform they are compiled on. Java (JVM also written in C but ....) on the other hand uses specific platform independent data types in particular all strings are unicode. In order to communicate with the underlying sqlite executable the java library must use JNI, which (usually) involves some conversion of data types and character encoding. This can be very cpu intensive particulary when converting C strings to unicode and back again. Having said all that I have used the sqliteJDBC jar a lot and never really noticed any pe

Categories : Java

unable to open database file in sqlite (using finisar.sqlite)
So a number of things could be going wrong here: The folder the SQLite database is in, you don't have Write permissions to. The database is already open by another SQLiteConnection. The connection string is wrong. I think this one is unlikely because it's clearly a variable you're pulling the connection string from and I have to believe other times you wanted data you used the same string. To remedy #2 you should always access your data like this: using (SQLiteConnection c = new SQLiteConnection(f_strConnStr)) { c.Open(); ... }

Categories : C#

Python with SQLite. SQLite data into variable
Your problem is that you are calling fetchone() two times inside the loop. There is nothing magical about the while loop that corresponds to rows; instead it is a side effect of the call to fetchone() that advances to the next result row. The first print outputs the first row; the second (with "why") would print the second row (if it existed).

Categories : Python

Transactional SQL with Sails.js
We're working on native support for transactions at the ORM level: https://github.com/balderdashy/waterline/issues/62 Associations will likely come first, but transactions are next. We just finished GROUP BY and aggregations (SUM, AVG, etc.)

Categories : Node Js

Sails.js - One to Many mapping
Sails.js doesn't support association yet, but they're working on it: https://github.com/balderdashy/sails/issues/124#issuecomment-21690561 Also see: How to perform SQL Joins in Sails.js/Waterline? For now I would just reference ID's and/or use the .query() method.

Categories : Javascript

Can Sails.js application be run in Apache
No, you can't run Javascript on Apache. But you can run Javascript on Node.js and proxy pass your request from Apache to Node.js. You can read more about proxy pass, Apache and Node.js here

Categories : Apache

Sails.js + PageDown -- How to call the add-on
if you add a service (./api/services/) with the name pagedown.js containing: module.exports = require("pagedown"); you have the pagedown object globally available.

Categories : Node Js

sails.js: how to update model
So you figured out your problem, sort of. req.body is already an object. But you really should sanitize it before you put it into your update and then save the object. There's a lot of reasons for this but with Mongo when you get only a partial object you'll replace the object in the collection which, in your example with a user, could be bad. When I send users to the frontend I cull off things I don't want transmitted all over like passwords. The other reason is the golden rule of web application development - never trust the client! I'd start with something like: var user = User.findOne(req.body.id).done(function(error, user) { if(error) { // do something with the error. } if(req.body.email) { // validate whether the email address is valid? // Then

Categories : Json

Node JS Sails Two Different Databases
If you're asking about Sails.js and its Waterline ORM, it doesn't appear that Oracle has a compatible adapter available as of yet. https://github.com/balderdashy/waterline

Categories : Javascript

Sails.js - file upload
This will get you most of the way there: https://github.com/balderdashy/sails/issues/27 You can use https://github.com/aconbere/node-file-utils to create directories, etc. Install it with npm install file Require file in the module having code similar to that in .../sails/issue/27.

Categories : Javascript

How to access external api using sails.js?
The host shouldn't include the protocol: var http = require('http'), options = { host : "graph.facebook.com", port : 80, path : "/"+other.uid+"/likes?access_token="+other.token, method : 'GET' }; If you want to use https, use the https module instead of http, and use port 443. And don't forget to add req.end() when you're done with the request.

Categories : Facebook

how to configure https in sails.js
If you're using the latest v0.9 (and maybe some versions of v0.8) take look inside of config/bootstrap.js. You should be able to access your express app via the sails.express context. From there I think you should be able to do with it what you want to... Also someone in the #sailsjs irc channel said this worked for them module.exports.bootstrap = function (cb) { var fs = require('fs'); sails.config.express.serverOptions = { key: fs.readFileSync('ssl/key.pem'), cert: fs.readFileSync('ssl/cert.pem') }; cb(); };

Categories : Node Js

Complex database queries in Sails.js
For complicated queries refer to this answer by particlebanana, one of Sails.js core contributors. As an alternative to perform joins, you can use the associations branch.

Categories : Javascript

How do I connect bower components with sails.js?
Note: the following answer is no longer completely relevant to the current version of SailsJS because there is no support for the linker folder as of SailsJS 0.10. See: Sails not generating linker Original answer: I was able to figure out a solution for this, which is actually pretty simple. I had not realized you could configure where bower places it's files. Create a .bowerrc file and change the directory where bower components are installed, in the case of Sailjs they should be put into the assets folder. /* * Create a file called .bowerrc and put the following in it. * This file should be in the root directory of the sails app. */ { "directory": "assets/linker/bower_components" } Sails will then use grunt to copy them to the .tmp/public/assets folder whenever a file is

Categories : Javascript

Sails.js + Passport.js authentication through websockets
Please try to check for req.session.passport.user. It will contain user info when logged in, and will be undefined otherwise. Works for me with any type of request. I think this happens because in case of WebSocket request, "req" is actually fake request object. It created and passed directly to Express' router, bypassing all Express' middleware, including Passport's one

Categories : Node Js

How to implement ReST services with Sails.js?
Yes it can. Sails JS allows you to easily build a RESTful API, essentially with no effort to get started. Also, websockets (through socket.io) are integrated by default into the view and api. To create a fully RESTful app from the ground up, it actually requires no JS. Try: sails new testapp cd testapp sails generate model user sails generate controller user cd <main root> sails lift The CRUD (Create, Read, Update, Delete) actions are already created for you. No code! You can create a user in your browser by doing the following: HTTP POST (using a tool like PostMan) to http://:1337/user/create { "firstName": "Bob", "lastName": "Jones" } Next, do a GET to see the new user: HTTP GET http://:1337/user/ FYI - Sails JS uses a default disk based database to get you

Categories : Rest

How to get socket.io.js file from server using sails.js
The handshake error is explained here: https://github.com/balderdashy/sails/wiki/sockets#500-error-handshake-error-returned-from-socketio-request You do not have a session with the server so when socket.io.js is included, there is no session cookie for it to use and the handshake fails. You need to make a successful request to the server beforehand that opens a session. This would need to be a CORS request since your server and their server are on different domains. CORS would need to be enabled on the server side using the method explained here: https://github.com/balderdashy/sails-wiki/blob/0.9/config.routes.md#cors-cross-origin-resource-sharing

Categories : Angularjs

Sails+Passport: Logging out won't work
I used Passport with Sails also, my routes.js has logout as a "post" 'post /logout':{ controller: 'user', action: 'logout' }, and my logout function is the same, may fix your issue? Here is my view call also if it's helpful: <form action="/logout" method="post"> <input type="submit" value="Log Out"/> </form>

Categories : Node Js

Sails.js. How counting online users?
I'm not sure if it's the best way, but one way could be to use a web socket. On the client side, when someone connects, it could send the username or email, so you can keep a list of online user on the server side. Then on the web socket disconnect, you remove the user from your list of online user. There you go, you have the count of online users. Take a look at http://socket.io/ for more information on how to use web sockets I hope it helps. :)

Categories : Javascript

Auto reloading a Sails.js app on code changes?
You have to use a watcher like forever, nodemon, or something else... Example Install forever by running: sudo npm install -g forever Run it: forever -w start app.js To avoid infinite restart because Sails writes into .tmp folder, you can create a .foreverignore file into your project directory and put this content inside: **/.tmp/** **/views/** **/assets/** See the issue on GitHub: Forever restarting because of /.tmp.

Categories : Node Js

Where is title or app name for sails.js (using node.js and express.js)?
You can create any file in config/ directory, for example config/app.js which contains comething like this: module.exports = { appName : 'My App' }; Any property of exported object become an option of Sails` config. appName property is used as application title. For example, in default layout: <title><%- title %></title> where title === sails.config.appName === 'My App' By default appName config variable is set to 'Sails'.

Categories : Node Js

Can't add view as html page (sails.js)
Why do you want to directly pass a file with .html extension , why not just '/fooDetails': { view: 'foo/details' } And then paste all your html in details.ejs ?

Categories : HTML

Using sails.js with an existing postgres database
I am the author of Sails-Postgresql. Sails has an ORM called Waterline that it uses for managing data. The default setting assumes that you would want to auto-migrate your database to match your model attributes. Because Postgresql is a SQL database the Sails-Postgresql adapter has a setting called syncable that defaults to true. This would be false in a NoSQL database like redis. This is easy to turn off if you want to manage your database columns yourself. You can add migrate: safe to your model and it won't try and update your database schema when you start Sails. module.exports = { adapter: 'postgresql', migrate: 'safe', attributes: { title: { type: 'string' } } }; Sails doesn't have anything like migrations in Rails. It uses auto-migrations to attempt to remove this fr

Categories : Node Js

Sails.js server not starting anymore
Hmm-- looks like port 8080 isn't available. What happens if you try to switch the port? You may have another server running on that port. Or in some cases, hosts require the hostname to be set. I'd try switching the port first though.

Categories : Javascript

Create config variables in sails.js?
You can create your own config file in config/ folder. For example config/myconf.js with your config variables: module.exports.myconf = { name: 'projectName', author: 'authorName', anyobject: { bar: "foo" } }; and then access these variables from any view via global sails variable. In a view: <!-- views/foo/bar.ejs --> <%= sails.config.myconf.name %> <%= sails.config.myconf.author %> In a service // api/services/FooService.js module.exports = { /** * Some function that does stuff. * * @param {[type]} options [description] * @param {Function} cb [description] */ lookupDumbledore: function(options, cb) { // `sails` object is available here: var conf = sails.config; cb(null, conf.whatever); } }; //

Categories : Node Js

sails-mysql schema datatypes
I am the author of Waterline, sorry you couldn't find what you needed in the docs, we are constantly working on adding to them and keeping them up to date. You are very close on your schema. Waterline currently doesn't support a database level ENUM type but we have validations that will allow you to end up with the same end result. module.exports = { // Disables Automatic ID generation // (allows you to use a FLOAT type for your ID) autoPK: false, // Disables Automatic Timestamps // You will need to manually update your timestamps, usually best to leave this // on and remove the updated_at and created_at attributes below to let Waterline // keep these up to date for you autoCreatedAt: false, autoUpdatedAt: false, attributes: { id: { type: 'FLOAT', p

Categories : Mysql

How to use Anchor, the validation system of sails?
Validations are added to the attributes object on a model. You can find a list of available validations at: Sails Wiki - Models. They are run whenever you are submitting data to be written to a datastore. So on create Waterline will validate all the attributes you submit and on update it will validate the attributes you are trying to change. An Example model with validations would look something like: module.exports = { attributes: { firstName: { type: 'string', minLength: 3, required: true }, lastName: { type: 'string', minLength: 3, required: true }, email: { // types can be a validation type and will be converted to a string // when saved type: 'email', required: true }, sex: { type: '

Categories : Node Js

Sails.js - passing data to a view
Try <%= apps[applicant].name %> It's just like for loop works. applicant is an index in apps array. Edit: Better way is to use javascript array's built in method forEach, because this way you avoid cycling through elements, inherited from apps's type (for example, elements, assigned like this: apps.__proto__.foo = {name: "bar"} or Array.prototype.foo2 = {name: "pi222"}). <% apps.forEach(function(applicant) { %> <li><%= applicant.name %> <%= applicant.email %></li> <% }); %> P.S. Of course this javascript's method (forEach) wouldn't work in IE <= 8(if you consider to use it in browser). But we are inside NodeJs, which is built on top of V8 engine. So this will work, anyway.

Categories : Javascript

How to serve a bootstrap template in sails 0.9?
Sails 0.9.x has moved to use Grunt for handling assets. This allows you to do many different kinds of pre-compilation and asset handling. By default, automatic asset injection into your views and layouts is not available. We have added a flag you can include when generating a new sails project that will create a folder within your assets folder and automatically inject any files into you index.html or layout file. This should only be used for development. sails new <project name> --linker Now you will have a folder titled linker under your assets folder that you can place files in to have them automatically linked. It will also add some tags to your index.html file and your layout file to know where to inject the various JS, CSS and templates. You can read more here: Sails Wiki -

Categories : Node Js

how to access assets/images from the view in Sails.js?
<img src="/images/placeholder.png"> should work. the assets folder is the equivalent to adding a folder with the static middleware in express. asset documentation

Categories : HTML

How to properly add HOST using sails-mongo adapter?
Ended up having to update sails.js to version 0.9.3 and using the sails-mongo adapter as such: module.exports.adapters = { // If you leave the adapter config unspecified // in a model definition, 'default' will be used. 'default': 'mongo', mongo: { module : 'sails-mongo', host : 'localhost', user : 'Chris', password : 'PASSWORD', database : 'localHostTestDB' }, // In-memory adapter for DEVELOPMENT ONLY memory: { module: 'sails-memory' }, // Persistent adapter for DEVELOPMENT ONLY // (data IS preserved when the server shuts down) disk: { module: 'sails-disk' }, // // MySQL is the world's most popular relational database. // // Learn more: http://en.wikipedia.org/wiki/MySQL // mysql: { // module: 'sails-mysql',

Categories : Javascript

How to perform SQL Joins and Relations in Sails.js and Waterline?
Associations are officially Supported in Waterline Overview From the docs: With Sails and Waterline, you can associate models across multiple data stores. This means that even if your users live in PostgreSQL and their photos live in MongoDB, you can interact with the data as if they lived together in the same database. You can also have associations that span different connections (i.e. datastores/databases) using the same adapter. This comes in handy if, for example, your app needs to access/update legacy recipe data stored in a MySQL database in your company's data center, but also store/retrieve ingredient data from a brand new MySQL database in the cloud. Supported Association Types One to Many Many to Many Cross-adapter Dominance One to One One Way Planned Association T

Categories : Node Js

How to use headers for session key rather than a cookie in node's Sails.js
Sails.js 0.9.x This is not documented anywhere, but you should be able provide custom middleware to the underlying express object by doing the following: config/express.js var sessionware = require('mycoolmiddleware'); modules.exports.express = { customMiddleware: function (app) { app.use(sessionware.sessionHeader()); } }; Sails.js handles this here: https://github.com/balderdashy/sails/blob/v0.9.16/lib/express/index.js#L162 Sails.js 0.10.x As of Sails.js 0.10.x, they now document how to provide custom middleware here: http://sailsjs.org/#/documentation/concepts/Middleware

Categories : Javascript

Calling super method in sails.js controller
Update: for Sails >= v0.10.x, see the comment below from @naor-biton If you want to access the default implementation (the blueprint), as of v0.9.3, you can call next() (the third argument to your controller). This is because Sails is based on the Express/Connect concept of middleware, allowing you to chain things together. Please note that this behavior may change in a subsequent version, since next() is also how you call your default 404 handler (config/404.js) for actions which don't have a blueprint underneath them. A better approach, if you're interested in using the blueprints but running a bit of logic beforehand, is to leave the controller action undefined and use one or more policies, which will be run beforehand.

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.