Configuring Express Generator to use Pug instead of Jade - javascript

I installed Express Generator for Node.js but when I created an example app, I noticed that Jade is deprecated to Pug. I installed Pug, but I still need to tell express generator to use it each time. I've been reading about the subject and it's telling developers to just change the file names manually, but is there a way for this to work out of the box? How do I do that?

Express defaults to Jade but if you wish to pug as a template engine instead of using Jade.
You must type
express --view=pug myapp
This will create a new application called "myapp" using pug by default.
For a more in dept explanation type
express -h
this will show you the available commands, one of the commands is -v
--view add view support
Reference: https://expressjs.com/en/starter/generator.html

I made two mistakes trying to follow the above docs. It's because I'm still getting used to installing packages locally and globally.
2 Mistakes:
I. npx express-generator
This installed it locally, making express unavailable in the command line terminal.
When I installed it globally, I had access.
II. starting in a folder on Atom, an IDE. Express-generator creates a folder for you, so you start in the terminal outside of a folder, such as your desktop.
9 Steps to solution:
Use the terminal in your desktop directory, not an IDE.
Do not create a folder or any file.
Install express-generator globally, not locally.
sudo npm express-generator
Verify you have access by: express -h
Type: express --view=pug my app
Change directories to myapp folder on desktop
npm install
DEBUG=myapp:* npm start
open your browser to http://127.0.0.1:3000/

I think this issue come when npx express-generator is used alone (for those who have node versions above Node.js 8.2.0).
for node versions 8.2.0 or above,
Navigate to the directory where you want to create the app
npx express-generator --view=pug myapp
This will create a myapp folder in the directory with required .pug
files instead of .jade files
for earlier node versions you can find the required steps here express
application generator documentation

npx express-generator --view=pug install.
this should do the trick

Related

Electron with Vue.js, not using a boilerplate

Not using a pre-existing boilerplate like electron-vue, I'd like to set up a Electron app with Vue.js. What is the procedure to do so, specifically for a beginner?
So far,I have installed vue cli globally with NPM, created my project with vue create, then installed electron into it with npm install electron.
From here is where everything falls apart. The article I was following specifies starting the app with dev, which runs: "NODE_ENV=DEV vue-cli-service serve & sleep 5 && NODE_ENV=DEV electron app.js". For whatever reason, this doesn't work. Comments on the article seem to suggest these commands are linux formatted, but no one has provided a windows formatted equivalent.
electron . starts the app, as expected, but vue components just dont work. Adding a basic <script src="> tag to the vue CDN at the top of the index.html works, and causes it to work, but ideally I'd like the electron app to work offline, which I believe was the point of using vue-cli as opposed to just importing it from the CDN.
Is there a simple way to do this? or would I be better off just downloading vue manually, throwing it into a folder in the electron app, and loading it with a script tag?
The easiest way to create an Electron app with vue.js as the frontend framework:
install vue-cli 3:
npm install -g #vue/cli
create a project (be patient because it may take a while):
vue create myproject
cd myproject
add and invoke the generator of vue-cli-plugin-electron-builder (it will automatically set up electron for you and let you check changed files):
vue add electron-builder
test your app:
npm run electron:serve
or build your app:
npm run electron:build
See more in this guide: https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/#to-start-a-development-server
This works in Windows Powershell if all PATH variables to vue-cli-sevice and electron are correct:
set NODE_ENV=DEV ; vue serve ; timeout 5 ; electron app.js
Note that the new version of vue changed some commands:
https://cli.vuejs.org/guide/installation.html
Windows command help:
Setting and getting Windows environment variables from the command prompt?
How do I run two commands in one line in Windows CMD?
What solved the issue in the end was changing relative paths to absolute.
Also this was useful: https://nklayman.github.io/vue-cli-plugin-electron-builder/

Using Node package in NativeScript app

I am learning NativeScript. For example, I would like to include this Guid generator package in my NativeScript app. My question is, how? I look at the directory structure generated by the command-line tool and I see the following relevant pieces:
node_modules
app
tns_modules
package.json
package.json
Do I add node-uuid to the ./package.json or the ./app/package.json? How do I reference it in my app then? For example, if I want to use uuid from the app.js file, what does that look like? I'm a little confused because of the package structure of NativeScript and how things actually get loaded at runtime.
Thanks
Run npm install from the root of your {N} app.
npm install --save node-uuid
The dependency will be added to the outer package.json.
And then in your app.js file, just use it like usual.
var uuid = require('node-uuid');
When you run tns run <platform> or tns build <platform>, the modules inside node_modules/ will be copied to folder under platforms/, take Android for example, it will be at platforms/android/assets/app/tns_modules/node-uuid. The building process is completed under platforms/ directory.

Using stellar-lib api with Meteor

this is probably a silly question but am new to Meteor and struggling a bit. I want to build a stellar app that tweets when you get stellar. There is a nice Javascript API stellar-lib that works on node, but im unsure how to access the modules in Meteor...
I'm also building an app with Meteor and stellar-lib and have found two options:
1) You can manually copy over the built stellar-lib.js or stellar-lib-min.js from the build/ directory from either the github repo or the node_modules folder you installed it to when you ran the npm install command.
If you do this, you will have to copy the .js file to client/compatibility, otherwise stellar-lib will not work (note: this means you can only use Stellar on the client).
2) If you need it on the server, you can also have browserify wrap stellar-lib for you, then copy the output to lib/ in your Meteor app's root directory. I did this in my repo here with gulp.
Here's a short explanation to how 2) works:
.gulp is where I'll install my NPM modules where they will be ignored by the Meteor build environment (because the folder is hidden).
In deps.js, I require the modules I would want to use in my Meteor app as I would if I was using them in a traditional node.js app. package.json defines the modules I'll install with NPM and the gulpfile.js describes a build task that will resolve my require statements and output a single deps.js file that includes my dependencies to my Meteor app's lib/ folder.

Grunt distribution doesn't include node_modules

I'm writing an application using Grunt as my build tool. I used the Yeoman generator angular-fullstack. The app is a Node.js app with Express on the backend. While developing, things work fine. If I build the distribution though, I can't deploy it to my server because none of the required npm dependencies are available, like Express for example. It's the first time I build this kind of app, so I assume I'm missing a step since the Gruntfile.js is still all defaults.
The "node_modules" folder is traditionally not included into source code repositories, for various reasons.
If you set up your node application correctly, however, and you have a "package.json" file where all dependencies are listed, then you just need to run npm install to download and install npm modules.

can not find module express --on windows

I use "npm install -g express" on windows console.but when I try to "node app.js", it shows me the error"can not find module express",I had set the environment variable"NODE_PATH",but nothing happen ,I need your help,Thank you!
Globally installed modules aren't accessible without full path. You need to install express in your project directory or it parents. Check out documentation about module loading.
npm allows two options on how to install a module: locally and globally.
A global installation (done using npm install -g xyz) is for providing some tooling system-wide. Related to express this provides the global express bootstrapper that you can use to create an initial frame for your app by simply typing: express .. If you need help on what you can do with this command, check out its help parameter: express --help.
In contrast, a local installation of a module provides this module for a specific app. A local installation is always made to an app's node_modules folder. When you try to require a module, Node.js searches the this folder for the requested module.
Hence, it is perfectly fine to have express installed multiple times: Once globally for the bootstrapper, multiple times locally (once per app).
So, to cut a long story short: To make your app run, install express locally using npm install express and that's it :-).

Categories

Resources