I am trying to use passportjs with Mojito by doing the following:
1) after installing Node JS and Mojito
2) created a Mojito app
3) created a Mojito
4) included passport as a dependency in the package.json of the Mojito app
5) ran npm install (it fetched passport into the node_modules directory, which is in the app dir)
6) in the function for the init action of the controller (in controller.server.js of the mojit created in step 3), I am requiring the passport module (this.passport = require('passport')), however Mojito complains with the following error:
/usr/local/lib/node_modules/mojito/node_modules/yui/yui-nodejs/yui-nodejs.js:1147
throw (e || new Error(msg));
^
Error: Cannot find module 'passport'
I've tried adding passport to the requires array that is passed to the YUI.add function in controller.server.js and according to the logs the mojito dispatcher is dispatching an instance of the my mojit/index with the passport module, however it also warns: [YUI-WARN] yui: NOT loaded: passport
Any ideas of what I might be doing wrong or any example of using any non-YUI nodejs module in Mojito?
This has been solved at: http://developer.yahoo.com/forum/Yahoo-Mojito/Using-Passport-JS-with-Mojito/1347478967128-30d8251c-4103-49dc-b555-bec39e9ebe1d
Solution: append the NODE_PATH environment variable with: ./node_modules:/opt/local/lib/node:/opt/local/lib/node_modules
Two things:
passport is not a YUI module, so you can't add it to the requires array in your controller. Instead, you need to require it as a regular node module using require('passport)`
there is a known issue in mojito/yui (which is going to be solved with YUI 3.9.0), where local node modules will not be recognized thru require() if you're using mojito start, which is running globally from the mojito cli. The solution is to not rely on the global cli to boot your application, and instead use ./node_modules/mojito/bin/mojito start from the app folder.
Related
Has anyone successfully deployed a SvelteKit app using npm pg to Netlify/Vercel/Cloudflare? My local dev implementation works just fine with how I have it set up ( db.ts file with a query function in lib/server, and then using endpoint actions and the load function in +page.server.ts files)
My build errors are as follows:
node_modules/pg-connection-string/index.js:3:18: ERROR: Could not resolve "url" node_modules/pg-connection-string/index.js:4:17: ERROR: Could not resolve "fs" node_modules/pg-pool/index.js:2:29: ERROR: Could not resolve "events" node_modules/pg-protocol/dist/parser.js:9:41: ERROR: Could not resolve "assert" node_modules/pg/lib/client.js:3:27: ERROR: Could not resolve "events"
And many of the above display a previous log message with something along the lines of:
✘ [ERROR] Could not resolve "buffer"
node_modules/safe-buffer/index.js:3:21:
3 │ var buffer = require('buffer')
╵ ~~~~~~~~
The package "buffer" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
I've been trying to get it to just build and it seems like it isn't able to use the pg package because it isn't a true node server environment. For each adapter it attempts to build with (except the node adapter) it refuses to build anything to do with the pg npm package. I could be wrong about the why, but my question about the how remains.
My hope is to avoid something like Prisma (which hasn't been working for me either) and I am trying to do this as "intended" meaning that I want to use SvelteKit as both the front end and the true backend. So an additional express server or the like is not the solution I'm looking for.
EDIT: I have also successfully deployed the app to Azure using the node adapter, but pg AND Postgres.js both do not work.
I've got a challenge to read a txt file that located in the same directory as my app.js.
In the challenge I can't use require so I can't import fs.readFileSync to my app.
Looking for other ways to console.log the txt content. Any ideas?
Without using require explicitly, you can use: module.constructor._load or process.mainModule.constructor._load
const fs = module.constructor._load('fs');
console.log(fs.readFileSync('./test.txt'));
Note that process.mainModule will be undefined if there is no entry script. (Not your case)
Of course this shouldn't be used in production code, since it's an undocumented API and may change. But will do for your challenge.
forgot to mention that I have to run it as node app.js
Otherwise you could use ES6 modules too, but that requires an additional flag: node --experimental-modules app.js
Have an application that has a angular 2 front end and node backend api that provide data for the front end. The node backend is using the npm config module to provide environment settings depending if the application is running on production or stage. I would like to use the same config module within the angular front end.
In node all you do to get the correct config settings is to require config
var config=require('config');
The config files also should in a /config folder of the application root where server.js is being loaded.
What is the best way to somehow require the config module into angular?
I would like to use the same config module in both angular and node environments.
Angular (or perhaps underlying XHR) is fussy about where it will pick up files from.
Can you get the server to serve up the config file as if it were data?
I'm developing a ReactJS app with Babel and Webpack. I am using the create-react-app facebook script so it handles the Webpack´s configuration. My problem is that I created a js file and add:
var childProcess = require('child_process');
But when I want to compile the new version i get the following error :
Module not found: 'child_process'.
I don't know what to do with this . I have read that adding custom configurations to the webpack.config.js may be the solution but i am using create react app so I don't have the Webpack configuration. I tried running npm run eject and create my own webpack.config.js but it doesn't work.
I hope somebody could help me.
You need to configure the correct target inside the webpack configuration: https://webpack.github.io/docs/configuration.html#target
module.exports = {
entry: './path/to/my/entry/file.js',
...
target: 'node',// we can use node.js modules after adding this configuration
};
Is there a way to use Webpack loaders in a Node app / Run a Node app in a Webpack environment?
For instance I've got a webpack config that has a style-loader. In my Node app I do the following:
import style from 'style.css'
console.log(style.someClass)
I wanna run it like $ node app.js
I've got an idea that might work, based on the Webpack NodeJS API. What if we put the code that we want to be able to use the Webpack environment (with the configured module loaders) into a module:
appModule.js:
import style from 'style.css'
console.log(style.someClass)
And require it with the following:
app.js:
import Webpack from 'webpack'
import MemoryFS from 'memory-fs'
...
webpackConfig.entry = 'appModule.js'
webpackConfig.output = 'appModule-out.js'
let compiler = Webpack(webpackConfig)
let mfs = new MemoryFS()
compiler.outputFileSystem = mfs
compiler.run(function (err, stats) {
require(webpackConfig.output)
})
Probably it won't work because the require looks for the output on the physical FS... Can we require from the memory FS? I have not tried it yet - Any idea?
Webpack loaders aren't transpilers or interpreters, they simple gather assets that are then handled off to something like SASS or a text concatenator; within the confines of Webpacks environment.
Thus it is not possible to reuse them in the way you want, because while you can of course import and call them (they're still just functions + classes), they don't convert CSS to JSON objects (they don't do this) as you have written in your desired example.
It looks like you just need a JS implementation of a css parser - have a look at https://github.com/reworkcss/css
You should be able to create a compilation targeting the node environment which you can ultimately run by simply calling node output.js and this will immediately execute the entry point module.
Be aware, in case that you're using a newer version of Node.js, that Webpack doesn't support the ES2015 module syntax, so you'll have to configure Babel for Node.js as well to transform the modules.