Run native Nodejs in AS400 / iSeries - node.js

I'm trying to run Node.js on AS/400 server in order to use Node.js toolkit for IBM i.
I have installed Node v6.14.4 and NPM 3.10.10 and I'm following this documentation to test node.js: https://developer.ibm.com/articles/i-native-js-app-ibmi-with-nodejs/#access-ibm-i-native-objects
I created the sample javascript file and when I run (from PASE terminal), I get this error:
node /home/njs/sample.js
/sample.js:1
(function (exports, require, module, __filename, __dirname) { #����ï¿
½ï¿½ï¿½K���M È ï¿½ï¿½#����� ]^
SyntaxError: Invalid or unexpected token
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.runMain (module.js:611:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:160:9)
I supposed there is a problem with npm and I tried with a very simple js file (an only one console.log) and I get the same error.

I have solved my issue. It was because an enconding problem.
I was creating javascript files with EDTF on AS/400 environment and that was a problem. I created a new file with notepad and upload by Navigator for i and works properly.

Related

SyntaxError: Unexpected token ... in serialport in node_modules

I hav been trying to run the vue-electron app. But the following error comes.
App threw an error during load
C:\newFolder02\pos4-desktop\node_modules\#serialport\stream\lib\index.js:103
const settings = { ...defaultSettings, ...options }
^^^
SyntaxError: Unexpected token ...
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:533:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\newFolder02\pos4-desktop\node_modules\serialport\lib\index.js:1:175)
The error comes from the following line.
const settings = { ...defaultSettings, ...options }
I use following tools
node 8.16.0
npm 6.4.1
electron 1.8.2
It doesn't work in Windows. But it works in Mac OS.
Any idea..?
I have found a solution. You can convert the ES6 code to original JavaScript code with Babel(https://babeljs.io/en/repl).
I converted the ES6 code to vanilla JavaScript through Babel. I ticked ENV PRESET in left sidebar. I set Electron to "1.8" and Node to "8.16". It worked well.
Babel Screenshot

How to fix the following error creating a node js class?

Hello I started creating a node.js class as follows:
'use strict';
let {google} = require('googleapis')
class Calendar {
calendarId : string;
However, when I test my code I got:
src/utilities/calendar.ts:6
calendarId : string;
^
SyntaxError: Unexpected token :
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
So I don't understand why I am getting that, I would like to appreciate suggestions to overcome the issue. My Node version is 8.16.0 and I am also using typescript
You are writing a typescript file, not a javascript file.
Node cannot automatically run typescript files. You need to:
install typecript
compile the file
run the output with node.js
Alternatively you could use a node like ts-node to execute your typescript right from the command-line.

Unexpected token import when trying to use pm2 on my react app digitalocean droplet

I am trying to host my app on DigitalOcean and getting it running with pm2 but run into this error:
/home/bcavenagh/social/src/index.js:1
(function (exports, require, module, __filename, __dirname) { import React from 'react';
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:27:21)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
I can get everything to run when using npm start but it doesnt work for pm2. In npm I am running from the ~/social folder but for pm2 I cd into ~/social/src and run:
pm2 start index.js
How do I get past this error?
You must compile/build your application, if not done so.
It will create a build folder (assuming you are using default configs with create-react-app), then you must point pm2 to the appropriate file (bundle.js or whatever you have) in that folder.
PM2 also supports running npm start command now. Checkout this question. What i usually do is, write a sh file, which updates code, does npm install and then at last runs pm2 command, for all deployments, which is similar to this answer in the previous link.

Can't run node project after formatting my linux partition

As the title says, I formatted my linux partition where I used as web development environment. Mainly I used MongoDB and NodeJS and both of them are installed correctly. But when I try to execute my main.js I get an error log. It must be something extremely silly that I'm not reminded of. Any help is appreciated. Error log:
SyntaxError: Invalid or unexpected token
at new Script (vm.js:74:7)
at createScript (vm.js:246:10)
at Object.runInThisContext (vm.js:298:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
Note that helpers.js is a node internal module.
Please download nodeJS command prompt for Linux or download by command
pacman -S nodejs npm
For More help : Visit the link
Node JS Installation Guide

Error while running Node.js program on IBM i (previously known as iSeries or AS/400)

IBM i Version : V7R2M0
node installation path: /QOpenSys/QIBM/ProdData/Node/bin
node -v : v0.12.17
I've created a simple console.log('hello world') program, while running getting following error
$ cd /QOpenSys/QIBM/ProdData/Node/bin
$ node /home/anoop/index.js
function (exports, require, module, __filename, __dirname) {
yntaxError: Unexpected token
ILLEGAL
at exports.runInThisContext
(vm.js:73:16)
at Module._compile
(module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
It is related to CCSID of file. You need to create file with 1208 CCSID or an ASCII codepage. So file is created as follows
$ touch -C 1208 index.js

Resources